by Ceric (Updated on 2012-07-24)
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 Attribute Types
- Creating Game Attributes
- Using 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.
Game Attribute Types
Unlike the large number of types available to Behavior Attributes, Game Attributes can have one of four types:
- Boolean (Yes or No)
Creating Game Attributes
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.
The new Game Attribute appears in the listing off to the right, sorted by category.
Using Game Attributes
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.
Since this Game Attribute has the type Number, we can use it almost anywhere we could use any other number.
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.
- 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.
- Game Attributes can have one of four types: Number, Boolean (Yes/No), Text and List.
- Saving a game amounts to storing Game Attributes.
- Loading a game amounts to reading in all stored Game Attributes.
i have deleted a setter attribute please help!!!
It is cool but, do I just attach it to a Actor Type and than click on it to activate?
There are only 5 types.
What about creating new Game Attributes types :
there are no Colour type, or Control one.
How can i save lists and maps ??
How can you save or submit sores in to a remote data base that all players no mater what pc or mobile device they are using can submit there scores to?
The explanation was not very clear but here is the basic Idea.
1-you make a game variable (assuming its default value will be 0)
2-Assign it a value.
3-if you want that value to be saved next time you open the game insert save game and then- function otherwise the next time you open the game the value of the game variable will be zero(or the default value).
4- The next time you open the game you have to insert the load save file function otherwise the value of the game variable will remain zero (because although you have saved its value you didn't load it yet)
my head hurts because this is all a little confusing, but I'm not giving in
@xandramas, the logic can be made in either one, depending on what you need
where am I supposed to create the logic? Is it a scene behavior? Is it an actor behavior?
This is cool, I get to create game Attributes without code, this is really helpful than a coding crud.