Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Game Attributes

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.

 

Contents

  • What are Game Attributes?
  • Game Attribute Types
  • Creating Game Attributes
  • Using Game Attributes
  • Saving
  • Loading

 

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:

  1. Number
  2. Text
  3. Boolean (Yes or No)
  4. List

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.

 

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.

Stencyl 2.2 Settings Button

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.

4-Click OK.

Create new Game Attribute


The new Game Attribute appears in the listing off to the right, sorted by category.


 

Tip: Game Attributes can also be created directly from Design Mode by clicking the Create New Game Attribute button.

 

 

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.

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).


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

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

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.

 

Summary

  • 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.


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!
5 Comments
imspikey
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)

1 3 months, 2 weeks ago
coolernow123
my head hurts because this is all a little confusing, but I'm not giving in
1 4 months, 3 days ago
herpeslurpy
@xandramas, the logic can be made in either one, depending on what you need
0 4 months, 5 days ago
xandramas
where am I supposed to create the logic? Is it a scene behavior? Is it an actor behavior?
0 5 months, 6 days ago
MDuru80
This is cool, I get to create game Attributes without code, this is really helpful than a coding crud.
0 1 year, 2 weeks ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.