Time for action – creating a Lives game attribute

The game file to import and load for this session is 5961_06_03.stencyl.

  1. Click on the Settings icon on the Stencyl toolbar at the top of the screen.
  2. In the left-hand panel of the Game Settings dialog box, click on the Attributes option.
  3. Click on the green Create New button.
  4. In the Name textbox, type Lives.
  5. In the Category textbox, change the word Default to Scoring.
  6. In the Type section, ensure that the currently selected option is Number.
  7. Change Initial Value to 3.
  8. Click on OK to confirm the configuration.
  9. We'll leave the Game Settings dialog box open, so that we can take a closer look.

What just happened?

We have created a new game attribute called Lives. If we look at the rightmost panel of the Game Settings dialog box that we left open on the screen, we can see that we have created a new heading entitled SCORING, and underneath the heading, there is a label icon entitled Lives, as shown in the following screenshot:

What just happened?

The Lives item is a new game attribute that can store a number. The category name of SCORING that we created is not used within the game. We can't access it with the instruction blocks; it is there purely as a memory aid for the game developer when working with game attributes. When many game attributes are used in a game, it can become difficult to remember exactly what they are for, so being able to place them under specific headings can be helpful.

Using game attributes

The attributes we have used so far, such as the Countdown attribute that we created in the Score Management behavior, lose their values as soon as a different scene is loaded, or when the current scene is reloaded. Some game developers may refer to these attributes as local attributes, because they belong to the behavior in which they were created. Losing its value is fine when the attribute is just being used within the current scene; for example, we don't need to keep track of the countdown timer outside of the Jungle scene, because the countdown is reset each time the scene is loaded.

However, sometimes we need to keep track of values across several scenes within a game, and this is when game attributes become very useful.

Game attributes work in a very similar manner to local attributes. They store values that can be accessed and modified, but the main difference is that game attributes keep their values even when a different scene is loaded. Currently, the issue of losing attribute values when a scene is reloaded is not important to us, because our game only has one scene. However, when our players succeed in collecting all the fruits, we want the next level to be started without resetting the number of lives. So we need the number of lives to be remembered when the next scene is loaded.

We've created a game attribute called Lives, so let's put it to good use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.216.249