Browse Search Popular Register Upload Rules User list Login:
Search:
Object Custom Variable Example

Image:
screenshot of the scene

Author: therestofguys

Group: Default

Filesize: 54.44 kB

Date added: 2023-03-17

Rating: 5

Downloads: 1254

Views: 332

Comments: 5

Ratings: 1

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

An object custom variable example I made for myself to understand it.
The goal is to create custom variables within an object.

----------

Custom variable within an object:

Similar to creating a "global" variable that applies to the whole scene, a "local" variable could be added to an object and only works when the object is interacted with.

Instead of entering scene.my.* into the console, enter a variable i.g. _variable = 0 into the textbox on the top left of an object's script menu.

For this type of variables, they will not be saved with the scene without the _ at the start of their names.

In this scene, I entered _array = ["A","B","C"] and _arrayslot = 0 separately into the purple square's script menu textbox. As Xray mentioned in the comment, it is also possible to enter many variables at once using ; as their separator, like this:
_array = ["A","B","C"] ; _arrayslot = 0

The purple square now contains a variable that is an array of three letters, and a variable that is a value of 0.

----------

Using the variables:

By using _array(_arrayslot) in the square's text parameter, I could call up one of the three letters within the array as its text.

The result I put together is that when onCollide, _arrayslot = _arrayslot + 1, which changes the text on the bouncy purple square.

To prevent _arrayslot adds pass 2, which breaks it, I limit the value with an if argument: _arrayslot < 3 ? {} : {_arrayslot = 0}
if _arrayslot is less than 3, no change, else _arrayslot = 0.

----------

Reference I used:
https://algodoo.fandom.com/wiki/Thyme - not all accurate info
Last edited at 2023/04/01 12:39:14 by therestofguys
Please log in to rate this scene
edit
Similar scenes
Title: for Xray
Rating: 5
Filesize: 19.35 kB
Downloads: 1123
Comments: 10
Ratings: 1
Date added: 2022/03/19 08:40:29
Made with: Algodoo v2.1.3
Rating: rated 5
download
Title: Call Up Array Value Example
Rating: 5
Filesize: 34.66 kB
Downloads: 1197
Comments: 0
Ratings: 1
Date added: 2023/03/05 19:08:41
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Laser Disk Reader(simple)(Fixed)
Rating: 5.625
Filesize: 6.74 kB
Downloads: 646
Comments: 1
Ratings: 2
Date added: 2009/09/06 02:30:08
Made with: Algodoo before v1.8.5
Rating: rated 5.6
download
Title: Custom variable inside a geometry
Rating: 5.4
Filesize: 3.11 kB
Downloads: 702
Comments: 1
Ratings: 4
Date added: 2009/05/26 17:23:08
Made with: Phun
Rating: rated 5.4
download
Title: Why Isn't This Working?
Rating: 5
Filesize: 24.76 kB
Downloads: 741
Comments: 4
Ratings: 1
Date added: 2014/02/13 22:41:24
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: All object terror CUSTOM poses
Rating: 5
Filesize: 0.81 MB
Downloads: 292
Comments: 0
Ratings: 1
Date added: 2017/09/22 13:00:37
Made with: Algodoo v2.1.0
Rating: rated 5
download
Hello therestofguys,

That example script that you show in the scene description is not correct and will not work: _array = ["A","B","C"] and _arrayslot = 0

That's because the boolean "and" cannot be used for creating custom variables. The correct way is: _array = ["A","B","C"]; _arrayslot = 0

In this corrected script, a semicolon separates the two commands. I also took a look at that link you provided for a Algodoo Wiki that someone created. Many of the tutorials and examples that I read in it are either vague or just plain incorrect. So, I would not rely on the information in it.
My bad, that was my bad phrasing. I've changed a few things now.
Okay, great!


Oops, hold on there. I have one more correction for ya. You stated "Naming the variable with a _ at the start makes them easier to spot." Well, my friend, that's not all the underscore is for. It is required for all local (also called "custom") variables. Without the underscore character, the variable will not be saved with the scene which means that it will not work whenever anyone downloads your scene and tries to use it! The underscore character is NOT needed for global ("scene.my...") variables.
Ooh, that cleared up one of my confusions, thanks!
YW!

Oh, wait... I just thought of one more thing (that stuff happens to us old people). You also do not need the underscore character for temporary variables. Temporary variables can be used within a calculation or within a function. For example:

{
tempVar = math.sin(sim.time);
tempVar > 0.5 ? {do this}:{else, do this}
}

After that code is no longer executing, tempVar will no longer exist.
Last edited at 2023/04/01 15:59:14 by Xray