Reading Arrays Using A Variable

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.

Use MyArray[Variable(myArrayIndexVariable)]

1 Like

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.

Capture

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)])

1 Like

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.

I think so

It looks like your ToString() has a lower case t as in toString() It should be capital T.

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