Browse Search Popular Register Upload Rules User list Login:
Search:
Call Up Array Value Example

Image:
screenshot of the scene

Author: therestofguys

Group: Default

Filesize: 34.66 kB

Date added: 2023-03-05

Rating: 5

Downloads: 1199

Views: 269

Comments: 0

Ratings: 1

Times favored: 0

Made with: Algodoo v2.1.0

Tags:
script

Scene tag

An array function example I made for myself to understand it.
The goal is to call up different values from an array.

----------

Custom global variable for an array:

By entering scene.my.array = ["A", "B", "C", "D", "E", "F", "G", "H"] into the console, scene.my.array only now exist as a global variable of this scene that is the array with 8 letters.

Note that each letter are contained within a "" since these are texts. If using only numbers then there's no need for "".


----------

To call up a value from an array:

It works like this: array(slot) = output.
So if I put:
scene.my.array(0) into the console, it will reply A
scene.my.array(1) into the console, it will reply B
...

Note that array slot positions start from 0 instead of 1.


----------

Making it interactable:

Knowing above, I can use another custom global variable for a changing (slot) value.
In this case: scene.my.number
Together with the array: scene.my.array(scene.my.number)

Like the array, entering scene.my.number = 0 into the console, so that scene.my.number exist in the scene.

In the green part, I made a little rectangle, and put the line into its text parameter:
{"" + scene.my.array(scene.my.number)}

Then I made these numbered squares, and edit each of them's onCollide parameter:
(e)=>{scene.my.number = 0} for the square with text 0
(e)=>{scene.my.number = 1} for the square with text 1
...

This way, when they collide with another object, in this case the little orange circle, the text in the green part displays an array's value corresponding to the slot position whenever scene.my.number changes.


----------

Reference I used:
https://algodoo.fandom.com/wiki/Thyme - not all accurate info
Last edited at 2023/04/18 19:30:42 by therestofguys
Please log in to rate this scene
edit
Similar scenes
Title: 16 pixel screen array (4x4)
Rating: 5.125
Filesize: 10.55 kB
Downloads: 664
Comments: 1
Ratings: 2
Date added: 2009/09/04 12:16:00
Made with: Phun
Rating: rated 5.1
download
Title: Object Custom Variable Example
Rating: 5
Filesize: 54.44 kB
Downloads: 1256
Comments: 5
Ratings: 1
Date added: 2023/03/17 10:47:39
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Country marble race 1
Rating: 5
Filesize: 1.19 MB
Downloads: 3596
Comments: 1
Ratings: 1
Date added: 2020/06/27 01:01:49
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Textures and Sines
Rating: 5
Filesize: 6.27 MB
Downloads: 817
Comments: 0
Ratings: 1
Date added: 2020/04/29 20:43:50
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Spring Reads Data
Rating: 5.625
Filesize: 12.07 kB
Downloads: 3107
Comments: 23
Ratings: 2
Date added: 2021/10/08 23:42:15
Made with: Algodoo v2.1.0
Rating: rated 5.6
download
Title: Array Functions
Rating: 6.3
Filesize: 115.11 kB
Downloads: 384
Comments: 18
Ratings: 4
Date added: 2020/03/27 23:01:01
Made with: Algodoo v2.1.0
Rating: rated 6.3
download