Image:
 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:
|
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 |