1: Getting Started
2: Building Logic
5: Game Mechanics
6: Advanced Topics
7: Testing & Tuning
8: The Last 10%
M1: Mobile - Intro
M2: Mobile - Basics
M3: Mobile - Services
M4: Mobile - Publishing
B: How-To Guides
3.0 Drafts (In Progress)
In the Attributes article, we introduced (Behavior) Attributes and discussed how they’re changeable values that are used within Stencyl's Behaviors.
Often times, however, we’ll want Attribute values to stick around longer than the lifetime of any particular Actor or Scene – sometimes even between gameplay sessions. For these cases, we can use a resource type called Game Attributes.
What are Game Attributes?
Game Attributes are changeable values that are stored along with a game and, thanks to saving and loading, can persist between gameplay sessions.
Like Behavior Attributes, Game Attributes have both a value and a type.
Unlike the large number of types available to Behavior Attributes, Game Attributes can have one of four types:
Note: Unlike normal lists, Lists can only contain Numbers, Text and other Lists that contain the same. Although you can dump anything in, if you plan to save this data, avoid putting in unsupported data types.
Consider our familiar vertical shoot ‘em up game.
A perfect use case for using Game Attributes is to keep track of the player’s score, since presumably we want the score to persist between Scenes.
Let’s perform the following to create a new Score Attribute from the Dashboard:
Note: As of version 2.2, the process for creating Game Attributes has changed. The changes are reflected below.
To start, once you've opened a game, click the Settings button in the upper left to open the master Settings dialog window.
1-Click the Attributes button in the dialog.
2-Click the green Create New button in the upper right area in the dialog window.
3-Enter a name (“Score”) for the Game Attribute. The other fields can be left to their defaults.
Tip: Game Attributes can also be created directly from Design Mode by clicking the Create New Game Attribute button.
Once they’re been created, Game Attributes can be used in Design Mode. You can find “getter” and “setter” blocks for each of them under Attributes > Game Attributes.
Tip: Game Attributes are always purple.
Note: If you want to use a new Game Attribute in a Behavior you already have open, you’ll need to reload the Behavior using Ctrl-R (Cmd-R on Mac).
As an example, say we want to increase the player’s score by 100 anytime a bullet collides with an enemy. The following simple logic does the trick, using both the getter and setter blocks for the Score Game Attribute:
Saving a game amounts to storing Game Attributes.
If we want to keep track of a player’s progress between gameplay sessions, we can do so by storing any data that needs to persist into Game Attributes and then by using the save block.
Let’s say every time the player enters a new Scene, we want to save the game. All we need to do is to use the save block. Score (as well as any other Game Attributes) will get saved automatically.
Loading a game amounts to reading in all stored Game Attributes. The developer can then choose what happens next (e.g., changing Scenes accordingly).
To load a game, just use the load block.
Note: There’s no way to “opt-out” certain Game Attributes from being saved. If you want to reset a Game Attribute’s value after performing a load, you’ll need to do it manually.
Last Updated: 2012-07-24 by Ceric
22104 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!