Using Director > Writing Scripts with Lingo > Using lists

 

Using lists

Lists provide an efficient way to track and update an array of data, such as a series of names or the values assigned to a set of variables. For example, if you know you will need to keep track of many names or numbers in your Director project, you may want to store them in a list. The list operator ([ ]) designates that the items within the brackets comprise a list.

You can create two types of lists with Lingo: linear lists and property lists.

In a linear list, each element is a single value. For example, this linear list is a simple set of numbers:

[100, 150, 300, 350]

In a property list, each element contains two values separated by a colon. One value is a property name, always preceded by a pound (#) sign; the other value is the value associated with that property. For example, the following statement sets the variable myList to a property list containing values for the properties #speed, #direction, and #weight. These could be the properties of an asteroid.

myList = [#speed: 155, #direction: 237, #weight: 8746]

Properties can appear more than once in a property list.

Both kinds of lists can be empty, containing no values at all. An empty linear list consists of two square brackets ([ ]). An empty property list consists of two square brackets surrounding a colon ([:]).

It's usually easier to manipulate a list by assigning it to a variable when you create the list. The value contained in the variable is actually a reference to the list, not the list itself.

For more information on lists, see list().