# Syntax

**URL:** <https://forum.kirupa.com/t/syntax/19035>\
**Category:** Uncategorized\
**Created:** [April 23, 2003, 5:57pm UTC](https://forum.kirupa.com/t/syntax/19035 "2003-04-23T17:57:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [April 23, 2003, 5:57pm UTC](https://forum.kirupa.com/t/syntax/19035/1 "2003-04-23T17:57:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 6:02pm UTC](https://forum.kirupa.com/t/syntax/19035/2 "2003-04-23T18:02:11Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 6:03pm UTC](https://forum.kirupa.com/t/syntax/19035/3 "2003-04-23T18:03:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 6:07pm UTC](https://forum.kirupa.com/t/syntax/19035/4 "2003-04-23T18:07:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 6:09pm UTC](https://forum.kirupa.com/t/syntax/19035/5 "2003-04-23T18:09:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 6:16pm UTC](https://forum.kirupa.com/t/syntax/19035/6 "2003-04-23T18:16:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 8:03pm UTC](https://forum.kirupa.com/t/syntax/19035/7 "2003-04-23T20:03:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 23, 2003, 8:34pm UTC](https://forum.kirupa.com/t/syntax/19035/8 "2003-04-23T20:34:49Z")

</div>

genius =)

thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 24, 2003, 6:45am UTC](https://forum.kirupa.com/t/syntax/19035/9 "2003-04-24T06:45:13Z")

</div>

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
