Scoring
A frequent question that comes up is how to handle scoring for a game. There are a bunch of different ways to do it, but the following demonstrates a simple example. If you would like to see a short video of how this is done, go to the
videos section and watch "Add High Scores and UI to your Game."
Tracking the Score

- Click on the Astronaut to access the World's class and add a custom property to the world called score. Note that this should be an integer valued property because we don't record fractional high scores.
- Create a behavior on an object that fires on the event that you would like it to. In the example below, this happens when one object contacts any other object. In the logic editor, use the "Add" action to add a value to the World's score property. Use whatever value you would like to increment the score.

Displaying the Score
- Create a new rectangle that will be used to display the score.
- Set it's "filled" attribute to false, or set the "fill color" to the desired color.
- Set the "draw border" attribute to false, or set the "border color" to the desired color.
- Set the "ignore physics" flag to true.
- Add a new behavior to the object.

- Select the "when the property of an object changes."
- In the left-hand panel, navigate to the "actors" tab, click on the World, and drag the World's score property into the event you just created.
- Click on the "this" tab. Drag the "text" property into the right hand panel.
- Navigate back to the World properties and drag the world's score property into the right hand side of the "set" statement (or ctrl-drag the property out of the event "when X is modified" ).
Setting a High Score

High scores should only be used as the result of end-game scenarios or significant events in the game. You do not want to be sending the high score to the server every time it is incremented.
- Create a new behavior for the end-game scenario. Generally this will be the result of losing a certain number of lives, colliding with an enemy, or some other such event.
- Drag in the "set high score" action.
- Navigate to the Objects tab, and drag in the World' score property to indicate the value that will be set.
Displaying the High Score Menu
The High Score menu allows you to display the end user's high score in relation to all of their friends.
As shown to the right, during the end-game scenario, drag in the "show high scores" action. This action allows you to display the high scores. It also signifies the end of a game, as the only options for where to go from this screen are to restart the application or customize it.