Syntax

i have a variable ‘val’ and 5 arrays ‘roomNums1’ - ‘roomNums5’ i want a script to search one of those arrays … i can get it to search one array but i can’t get it to search the array with the name ‘roomNums+val’

so if val = 2
i want it to search roomNums2

at the moment I’m just telling it to trace the array that I want (for testing purposes) and the script reads:

trace (roomNums[val]);

but that takes the 3rd value in the array and traces it if val = 2

i’m not sure how to add the value of the variable val onto the end of the array’s name so the correct one will be traced

thanks

arrays are zero based. if you have 5 values, say “a” - “e”

mA = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’];

trace(mA[0])

returns “a”

trace(mA[4])

returns “e”

thats why 2 returns the 3rd value.

ok, as for the rest of your problem, I am still a little unclear…

ohhh ok, I think I understand. give me a couple seconds.

Here is a file. it might help out a little. if not then ask:

oh and for a little explanation, put a number from 1-3 in the text box and then press the button. :slight_smile:

right … it almost helps

so if i change the code to read
trace(“roomNums”+val);
then if val = 2 then it traces “roomNums2” i need it to trace the values of the array that is called roomNums2 =)

almost.

you can’t just do

trace(“roomNums”+val);

you have to do this:

trace(_root[“roomNums” + val]);

because that groups the two together as a single variable/array name.

genius =)

thanks

Hi Shuga,
You know, before I posted V4 back to you, I played around with that for quite a while, I knew that splitting the arrays to make the search shorter was one of the issues you needed to solve. Well, I could not work it out at all, I won’t bore you with the different things I tried - all to no avail.
Well done to Jubba, I knew the solution was simple, but it only underlines the fact that this site is brilliant for problem solving and learning.

Good Luck

SteveD