Hardware Reference
In-Depth Information
FIGURE 3-14 Setting the start position for your sprite
Creating Variables: Including Health
Points for the Adventurer Sprite
In role-playing games, players (or rather, their characters) typically start with a certain
number of 'health points' or 'lives'. As you play the game, these points may decrease as
you encounter foes or increase when you collect certain objects or overcome obstacles.
You can create variables in Scratch to allow for values that change, and use these vari-
ables inside diferent scripts. You can set the health points to a certain value—for
example, 50—at the start of the game and create scripts that will add or take away
points when triggered—for instance, inding a useful tool might add 10 health points.
his feature will make the game more interesting.
A variable holds a value that can be changed. The health variable in your
adventure role-playing game is an example of a value that can be changed and
used inside different scripts.
1. To create a variable, click Variables in the Blocks palette and then click Make a
Variable. he New Variable window opens and asks you to type a name for your
variable.
2. Name your variable Health and ensure that For all sprites is checked before
clicking OK. Figure 3-15 shows the window with the correct settings.
Search WWH ::




Custom Search