Array Helper

The Array Helper file contains handlers that assist in working with arrays.

Loading this Helper

This helper is loaded using the following code:

rigLoadHelper "array"

The following handlers are available:

rigArrayElement()

Lets you fetch an item from an array. The function tests whether the array index is set and whether it has a value. If a value exists it is returned. If a value does not exist it returns FALSE, or whatever you've specified as the default value via the third parameter. Example:

put "color=red,shape=round,size=" into tArray
split tArray using comma and "="

-- returns "red"
get rigArrayElement("color", tArray)

-- returns 0
get rigArrayElement("size", tArray, 0)

rigArrayRandElement()

Takes an array as input and returns a random element from it. Usage example:

put "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson" into tQuotes[1]
put "Don't stay in bed, unless you can make money in bed. - George Burns" into tQuotes[2]
put "We didn't lose the game; we just ran out of time. - Vince Lombardi" into tQuotes[3]
put "If everything seems under control, you're not going fast enough. - Mario Andretti" into tQuotes[4]
put "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein" into tQuotes[5]
put "Chance favors the prepared mind - Louis Pasteur" into tQuotes[6]

put rigArrayRandElement(tQuotes) into gData["quoteOfTheDay"]

rigArrayKeys()

Takes an array as input and returns the keys of the array as numeric array.

rigArrayValues()

Returns all the values from the input array and indexes the array numerically.

rigArraySplice(tArray, tOffset, tLength)

Retrieve a portion of an array. Example:

put "red,blue,green,yellow,violet,black,white" into tArray
split tArray using comma

put rigArraySplice(tArray, 2, 3) into tSplicedArray
combine tSplicedArray using comma

-- Produces: green,yellow,violet

Note:  This works with numbered arrays only as LiveCode's arrays are not ordered.

rigImplode(tArray, tGlue)

Joins array elements with a string. Example:

put "red,yellow,blue,green" into tArray
split tArray using comma

get rigImplode(tArray, " - ")

-- Produces: red - yellow - blue - green

rigElementsList(tArray)

Returns a list of array elements, each on a seperate line.