Does 'exists' work on arrays?

J. Landman Gay jacque at hyperactivesw.com
Sun Mar 15 16:20:51 EDT 2015


On 3/15/2015 11:50 AM, Graham Samuel wrote:
> Still struggling with arrays: no results, no error messages,  no data… will get there no doubt. While trying to get there, I tried
>
>    put exists(myArray[“gpx”])
>
> I got ‘false’, but the IDE seems to say that the top key in this multidimensional array is “gpx”, so why isn’t it true?

"Exists" is only for card controls. Array elements are variables, so 
myArray(["gpx"]) resolves to the content of whatever is stored inside 
the gpx variable.

If you want to know whether there's a key named "gpx" then:

   put "gpx" is among the lines of the keys of myArray

If you want to know the content of the key named "gpx":

   put myArray["gpx"]

Devin had a cool way to explain arrays in one of our classes some years 
ago. He just held up an egg carton. That's an array. Each egg depression 
holds some kind of egg (a variable.) The egg carton can be big enough 
that each egg depression holds a whole different egg carton.

carton[1] = the egg in the first slot
carton[1][3] = the egg in the third slot of the carton that's in slot 1 
of the main carton

The slots can be named instead of numbered. The names identify the 
slots, not the contents:

carton["gooseEggs"] = the value of whatever is in the slot named 
"gooseEggs" in the main carton

carton["gooseEggs"]["Canadian"] = the value in the slot named "Canadian" 
of the carton that's named "gooseEggs" which is inside the main carton

And yeah, it gets confusing when the arrays get big.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com





More information about the Use-livecode mailing list