Array index - getting element by a number or string

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
heyvern
Posts: 30
Joined: Sun Feb 21, 2010 12:38 am

Array index - getting element by a number or string

Post by heyvern » Thu Mar 04, 2010 8:02 pm

I think I know the answer but I just would like confirmation. It is clear that you can't access an array value numerically if it is indexed with a string. However In the documentation it says there is a way to access "elements" in the array by looping or repeating using the key word "element".

I have an array that is indexed by strings:

Code: Select all

theArray["head]["static_values"]
theArray["head]["styles"]
theArray["head]["animated_values"]
This doesn't work:

Code: Select all

put element 2 of theArray["heads"]
I just want to make sure it isn't possible to access array elements numerically in any way at all before I go with the numbered index... numbers are probably better anyway.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Array index - getting element by a number or string

Post by FourthWorld » Thu Mar 04, 2010 8:28 pm

All arrays in Rev currently are associative arrays, using name-value pairs.

So you could use:

put theArray["head"]["styles"]

...but there is no integer associated with an array element unless you use integers as your keys:

theArray["head"][1]
theArray["head"][2]
theArray["head"][3]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply