View Full Version : syntax
shuga
April 23rd, 2003, 01:57 PM
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
Jubba
April 23rd, 2003, 02:02 PM
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...
Jubba
April 23rd, 2003, 02:03 PM
ohhh ok, I think I understand. give me a couple seconds.
Jubba
April 23rd, 2003, 02:07 PM
Here is a file. it might help out a little. if not then ask:
Jubba
April 23rd, 2003, 02:09 PM
oh and for a little explanation, put a number from 1-3 in the text box and then press the button. :)
shuga
April 23rd, 2003, 02:16 PM
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 =)
Jubba
April 23rd, 2003, 04:03 PM
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.
shuga
April 23rd, 2003, 04:34 PM
genius =)
thanks
SteveD
April 24th, 2003, 02:45 AM
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
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.