by captaincomic (Updated on 2016-04-20)
Maps (also known as dictionaries) let you store and access data using names as keys. Unlike lists, which are ordered and use numbers as keys, maps don't care about order and let you use textual names as keys.
For example, if you wanted to make a Map that associated Stencyl members with post counts, it'd look like this.
Maps can also mix and match different types as values.
Or, you could get fancier and use Maps as the data itself.
Maps are useful when you want to...
Lists are better if you want to...
How do you create a Map in the first place? Maps can be attributes, so like any attribute, there are two ways of doing this.
Assume that for both cases, we have created a Map Attribute called "myMap"
After attaching a behavior with a Map attribute to either an Actor or a Scene, you'll see this interface for adding initial data to the Map.
Alternatively, you can create a new Map using blocks and begin filling it up.
All blocks related to maps are located under Attributes > Maps.
Maps can be used as Game Attributes. This can be useful for defining tables and other large collections of data to use throughout the game.
Maps can be created as Game Attributes and pre-populated the same way as other Maps, namely only with Numbers and Text.
Note: You may also dump Lists & Maps into Maps at runtime as well as any other kind of data. If you plan to save your Maps out (via Game Attributes), there are restrictions. Skip down to "Saving & Maps" under Caveats.
As you may expect, you can set the value of a Game Attribute to a Map.
Note: Assigning values simply gets the Game Attribute to "point" to your Map. No copying is done, so modifying it modifies the one and only "copy" of that Map.
Be careful when saving out Maps as Game Attributes. Just like Lists, they can only contain contain Numbers, Text, and nested Lists or Maps.