by Jon (Updated on 2015-10-18)
If you've ever written a grocery list, you're prepared to use lists in Stencyl.
As you'd expect, lists are best used to store collections of things. You can use lists for things like:
In general, lists can be a good option any time you want to keep track of lots of information.
Aside: Internally Stencyl uses lists to keep track of created actors, what points in a collision actually collided, and so on. If you've used any block that begins with "for each" you've actually used a list already!
For Programmers: Lists are mutable lists. They are equivalent ArrayLists, Vectors, NSMutableArray or whatever you like to call them.
A list is an ordered collection of items. Each item in a list is made up of two parts:
Think of a list as a 2-column table.
The first column is the index. The second column is the value.
Indexes for lists start at 0, so the first item in a list starts at index 0, the second item is listed at index 1, and so forth.
Don't work with indices beyond the maximum one (or below 0). Your game will crash if you do.
All blocks related to lists are located under Attributes > Lists.
How do you create a List in the first place? Lists can be Attributes, so like any attribute, there are two ways of doing this.
Assume that for both cases, we have created a List Attribute called "myList"
After attaching a behavior with a List attribute to either an Actor or a Scene, you'll see this neat interface for adding initial data to the list.
Note: The second icon (the one under the +) lets you import a List from a text file. One line per entry. All entries will be treated as text.
Alternatively, you can create a new list on the fly and begin filling it up.
Lists can be used as Game Attributes. This can be pretty useful for defining stat tables and other large collections of data to use throughout the game.
Lists can be created as Game Attributes and pre-populated the same way as other lists, namely only with Numbers and Text.
Note: You are also allowed to dump in Lists into Lists at runtime as well as any other kind of data. If you plan to save your lists out (via Game Attributes), there are restrictions. Skip down to "Saving & Lists"
It should come as no surprise that you're able to set the value of a Game Attribute to a List.
Note: Assigning values simply gets the Game Attribute to "point" to your List. No copying is done, so modifying it modifies the one and only "copy" of that list.
As stated earlier, be careful when saving out lists as Game Attributes. They can only contain contain Numbers, Text and other Lists that follow the same rules.
Lists are great for storing sequential information, but if you need to store a "grid" of data? It turns out that lists are powerful enough that you store a List within a List, thereby bringing it up to 2 dimensions.
Come up with a scenario in which you need a 2D list and implement it.
Disclaimer: This challenge is just an exercise for practicing what you've learned. Part of what we're doing with Stencylpedia is getting you to think about the underlying concepts. Please do not regard this as best practice - it's just an exercise.
A veteran Stencyler has created a handy extension for 2D lists.