In most games there is a score of some type and the player will
usually have either health or lives (or both). Now, you can use the
variable and question actions to set this up yourself, but
GameMaker: Studio comes with a series of in-built variables
that deal with these things, and these variables have their
corresponding actions, which are detailed in this section.
With this action you can set the score to a value of your choice. Note that "score" is a global variable (see this section for more information: Variables And Variable Scope) and as such, this action can be placed in any object, meaning that (for example) you could have a destroy event for an enemy object that sets the score to 10 relative. Why relative? Well, as outlined in the introduction to actions, this will add 10 to the current score whereas if you do not check the relative flag it will just set the score to 10! You would normally un-check the relative flag and place this action at the start of a game to set the score to 0, for instance.
This action will check the value of the score against the value you input and return true if it meets the condition. The condition can be either equal to, greater than or less than and in this way you can have specific behaviours for an instance depending on the current value of the score variable.
You can use this action to draw the score variable anywhere on the screen, just provide the position and the caption to be shown beside the value. Please note that this action will only be valid when used in the Draw Event.
With this action you are telling GameMaker: Studio to clear the high score table. Warning! This cannot be undone!
Another global variable included with GameMaker: Studio is the one for lives (for more information on global variables see: Variables And Variable Scope). Normally you would set it to some value like 3 at the beginning of the game and then decrease or increase the number depending on what happens as the player progresses. Don't forget to check the Relative box if you want to add or subtract from the number of lives. At the moment the number of lives becomes 0 (or less than 0) a "no more lives" event is generated.
With this question action you can check whether the number of lives has reached a particular value. You indicate the value and whether the number of lives should be equal to, be smaller than, or be larger than the value. This can be used, for example, to limit the lives that a player can pickup while playing a game and so keep them from going above a maximum value.
You can use this action to draw the number of lives directly to the screen. You provide the position and the caption that must be placed in front of the number of lives, and then number of lives is drawn in the current font. Please note that this action will only be valid when used in the Draw Event.
Draw Life Images
Many games prefer to represent lives with some sort of graphic rather than straight text, and so GameMaker: Studio provides this action so you can get the same effect. You specify the position and the sprite image to be used for each life and at the indicated position the number of lives is drawn as images. Please note that this action will only be valid when used in the Draw Event.
GameMaker includes a built-in health global variable (for more information on global variables see: Variables And Variable Scope), and like the previous actions for score and lives, you can use this action to set and change the health value. To set the health to a specific value, leave the "relative" flag un-checked, but if you wish to add or subtract from the health value, then make sure that it is checked. Please note that this variable is clamped to be within the range of 0 to 100 (where 0 is no health and 100 is full health) and that when the health becomes less than or equal to 0 an "out of health" event is generated.
With this question action you can check whether the health has reached a particular value. You indicate the value and whether the health should be equal to, less than or greater than the value. One use for this is that when the player health gets below a certain amount you could make some object flash to draw their attention to the fact.
We have all seen a players health drawn in the game in the form of a bar that increases or decreases as the status of the player changes, well, this action permits you to draw the health variable in this way too. When the health is at 100 the full bar is drawn and when it is at 0 the bar is empty, and you can indicate the position and size of the health bar as well as the colour of the bar and its background.
Normally in the window caption the name of the room and the score is displayed, but with this action you can change this to show the score, lives, health and what the caption for each of these must be, or not, as you wish. This functionality is only valid for Windows, Ubuntu (Linux) and MacOS targets.