by Jon (Updated on 2015-10-18)


What are Lists?

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.

List Structure

A list is an ordered collection of items. Each item in a list is made up of two parts:

  1. A numerical index - in other words, where an item resides
  2. A value

Think of a list as a 2-column table.

The first column is the index. The second column is the value.

index value
0 eggs
1 bacon
2 cheese
3 apples
4 oranges
5 salmon

List Gotchas

List Operations

All blocks related to lists are located under Attributes > Lists.




The Future: We don't yet support reversing, combining or sorting lists, though these are all supported in a 3rd party extension. We do, however, support Maps/Dictionaries.

How to Create 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.

  1. Configuring the attribute with initial data.
  2. Creating it at runtime inside a behavior and setting the attribute's value to that new list.

Assume that for both cases, we have created a List Attribute called "myList"

Method 1: Configuring a List Attribute

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.

Method 2: Creating it on the Fly

Alternatively, 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 Attribute

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"

Setting the Value of a Game Attribute to a List

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.

Saving & Lists

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.


Challenge: Two-Dimensional Lists

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.

Looking for a 2D list extension?

A veteran Stencyler has created a handy extension for 2D lists.