|
Lingo 4.3: Lists READING: Chapter 16, pages 512-528 of D8D In PDF reading: Pages 398-401 File "listexample.dir" Lingo provides a powerful set of list manipulation commands. Here is an example that shows how to add items into a list. First, create the global list that the objects will be placed into: on startMovie global mylist mylist = list() -- same as mylist = [] endThen, attach a script to each cast member so that, when the user clicks on the sprite, that object will be added (append) to the global list.
on mouseUp
global mylist
mylist.append("eye")
end
Look in the Message window as you click on each item and you will see what is added to your list.
There is a list of list functions accessible via the Script window in Director (e.g. append, deleteOne, sort, setProp, etc.)
You can, of course, append and delete items from the list by executing code in the message window. For example, you could add and then delete an ear:
mylist.deleteOne("ear")
You could also find how many items are in a list and the list element at any position:
put mylist.getAt(1) -- same as mylist[1] put mylist.count -- same as count(mylist)Now you can have a button, for example, that will always give you the last element in the list. (You have to name it something other than "last" becaust it is a Lingo keyword): global mylast mylast = mylist.count put mylist.getAt(mylast) -- same as mylist[mylast] These commands will be useful in your next assignment. While you are looking at the lists, check the definitions of the commands
|
|
|
Maintained By: Takis Metaxas
|
|