Switch to Book Layout1: Getting Started2: Building Logic
3: Actors
4: Scenes
5: Game Mechanics6: Advanced Topics7: Testing & Tuning8: The Last 10%M1: Mobile - IntroM2: Mobile - BasicsM3: Mobile - ServicesM4: Mobile - PublishingA: Troubleshooting
B: How-To Guides
C: ReferenceD: Resources3.0 Drafts (In Progress)
|
||
|
Level: Intermediate
ListsContents
What are Lists?If you've ever written a grocery list, you're prepared to use lists in Stencyl.
Lists let you record pretty much anything in a predictable way. If you add apples to a list, and then add oranges, when you read the list apples will always come before oranges. However, lists are useful for more than just remembering what to pick up from the grocery store.
For Programmers: Lists are mutable lists. They are equivalent ArrayLists, Vectors, NSMutableArray or whatever you like to call them.
What are Lists useful for?Lists are best used to store, well, collections of things. You can use lists for things like:
Lists can be a good option any time you want to keep track of lots of information.
Note: 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!
List StructureA list is an ordered collection of items. Each item in list is made up of two parts:
Think of a list as a 2-column table.
List Gotchas
List OperationsAll blocks related to lists are located under Attributes > Lists. Operations
Getters
Creators
Coming Later: As of Stencyl 2.0, we don't support reversing, combining or sorting lists. These operations may be available in the future though! We're also looking into adding Dictionaries (also known as Maps), which map arbitrary keys to values.
How to Create ListsHow 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"
Method 1: Configuring a List AttributeAfter 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.
Method 2: Creating it on the FlyAlternatively, you can create a new list on the fly and begin filling it up.
Lists as Game Attributes
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. Creating a List as a Game AttributeLists 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"
|

















