Using Director > Writing Scripts with Lingo > Using lists > Setting and retrieving items in a list |  |

Setting and retrieving items in a list

Lingo lets you set and retrieve individual items in a list. The syntax differs for linear and property lists.

To set a value in a linear list:

Use the equals (=) operator. (You can also use the `setAt` command introduced in earlier versions of Director.)

For example, the statement `workerList[2] = "Tiffany"` makes Tiffany the new value for the second item in the list workerList.

To retrieve a value in a linear list:

Use the list variable followed by the number that indicates the value's position in the list. Place square brackets around the number. (You can also use the `getAt` or `getaProp` commands, which were introduced in earlier versions of Director.)

For example, in the linear list `set workerList = ["Bruno ", "Heather ", "Carlos "]`, the expression `workerList[2]` represents the second value in the list workerList. The value is Heather.

To set a value in a property list, do one of the following:

| Use the equals (=) operator. (You can also use the `setAProp` command, which was introduced in earlier versions of Director.)
| For example, the statement `foodList[#Bruno] = "sushi"` makes sushi the new value associated with the property Bruno.
| Use dot syntax.
| For example, the statement `foodList.Bruno = "sushi"` makes sushi the new value associated with the property Bruno in the list foodList.

To retrieve a value in a property list, do one of the following:

| Use the list variable followed by the name of the property associated with the value. Place square brackets around the property. (You can also use the `getaProp` or `getAt` commands, or the `getPropAt()` function, which were introduced in earlier versions of Director.)
| For example, in the property list `foodList = [#breakfast:"Waffles", #lunch:"Tofu Burger", #dinner:"Hungarian Goulash"]`, the expression `foodList[#breakfast]` represents the value associated with the property `#breakfast`. The value is Waffles.
| Use dot syntax.
| For example, using the `foodList` property list above, `foodList.breakfast` represents the value Waffles.