Refer to an array using a variable.
I can set them up and read a particular one so
MyArray.3 to look at the 4th item in the MyArray array
but how do I put a variable instead of manually typing in the .3 so i can use code to pick where on the list to look? So
MyArray.Variable
to look up in the list depending on what Variable is.
I’ve tried the format in the wiki help and couldn’t get it to work.
MrMen
November 5, 2022, 7:53am
2
Use MyArray[Variable(myArrayIndexVariable)]
2 Likes
So would StartX[1] look at the second item in the Array StartX. I’m testing to see if I can get it to work. When I set a text object to this it returns [object Object] when i set and object position using it it just disappears - I have two arrays one StartX with value 1 being 90 and same with Start y.
I’ve figure out other ways to solve my problem but I would really like to work out how arrays work.
Hi. We’re going to need to see your code. If you’re seeing “object object” I’m going to assume you’re missing a Variable() or VariableString
Examples:
Set text = ToString(Variable(StartX[1]))
Set text = ToString(Variable(StartX[Variable(index)]))
Set text = VariableString(StartX[1])
Set text = VariableString(StartX[Variable(index)])
2 Likes
It disappears with that code
it should be 90.
Thanks for the help
How are you assigning the value to StartX[1]? Is it spelled the exact same ways? Capitalization will get you everytime.
It looks like your ToString() has a lower case t as in toString() It should be capital T.
MrMen
November 18, 2022, 4:14am
10
Also, use VariableString(StartX[1])
. It’ll return the variable but in a string format.
Urrgh Thanks yes that got the text working sorry I missed that. I got it working with a variable reference as well thanks all.
1 Like