Attributes are essentially variables. Any time you need to record a number (or an angle, or a piece of text), creating a new attribute is probably the best way to do it. If you’re struggling with this concept, focus on the numeric aspect of attributes. For instance, say you’re building a racing game. Creating an attribute to record the speed of your racer gives you the flexibility to easily change that speed in a way that can be referenced in a variety of situations, such as accelerating, braking, and collisions. At the same time, another attribute might be used to record the amount of time it takes to go around the track, or your final score.
GameSalad comes with a large number of existing attributes in every game project, storing information about actors, scenes, and the game itself. These preset list of attributes control certain base activities, such as scene size, actor motion, and game time. There are also options for creating custom attributes for any information you may wish to store as the developer. We’ll touch on existing attributes briefly, and then discuss how to use custom attributes for anything in your game.
Attributes exist for your game, your scenes, and your actors. Game attributes can be accessed by all actor prototypes and instances so that they can be seen in any scene. Scene attributes can only be accessed in a particular scene but all actor instances in that scene can individually be edited to view, use, and modify those scene attributes. Actor attributes can only be accessed by an actor instance, but can be initially defined and used in an actor prototype so that all instance of that prototype can have predefined behaviors.
There are six different types of attributes:
- Boolean: these are true/false values. One example use for this could the status of a button or door, where “true” would be open / on, and “false” would be closed / off. All Actors start with at least one boolean attribute by default under “physics” in their attribute list to toggle whether or not the actor is movable. Boolean attributes can be changed to true or false with the “change attribute” behavior.
- Text: letter and number values. These are primarily used in conjunction with the “display text” behaviors to display scene titles, actor names, and much more.
- Integer: whole number values, such as 15, 0, 42, and 5801. Integer is one of the more versatile attributes. A few of the many possible uses are storing the game’s score, specifying the number of units to spawn, or keeping track of how many reward objects are left in a scene.
- Real: allows for decimal values, such as 3.582, 0.882, and -2.5. Obviously integers can work here as well. Real attributes allow developers to include fractional events, such as time ticking down (or up), pouring a volume of liquid, or hit point / damage records where fractions of a point can be dealt.
- Angles: allows for values from 0 to 359, representing the degrees of a circle. You can use decimal values here as well within this range. Angle attributes are primarily used with objects that rotate or have some sort of angular movement, including launchers, such as the cannon in our “cannon physics” template.
- Index: positive whole numbers, such as 0, 1, 58, 2804. Index attributes can fulfill many of the same roles as Integers, but have the interesting feature of being unable to store a negative number. For instance, an index attribute with a value of 4 that was told to subtract 6 would then have a value of 0, not -2.
Because you’ll be accessing the value held by this attribute from actor behaviors, rename it something that makes sense to you and you’ll be able to remember later – such as “race car speed”, or “blocks remaining”. At times, you’ll want to record the location of an actor – you can do this through attributes as well, and these attributes might be named something like “PlayerX” and “PlayerY”, to record the X and Y coordinates of the player.
