11. Scoring HUD Logic


Now that we have a visible HUD, we need to add logic to have it update when players score. This tutorial will add code to the ScoreHud to update the displayed text according to public properties which will be set by GameScreen whenever a goal is scored.

Adding Team Score Properties

First we’ll be adding properties to the Hud object for the scores of each of the players. We could do this purely in code, but Glue provides a convenient way to set the score values to integers.

We will be combining two Glue features for this:

  • Tunneling variables – Creating a variable in an entity which is tied to the variable of a contained object. In this case we’ll be creating variables which are tied to each of the score Texts’ DisplayText variable.
  • Built-in casting of the variable type – although DisplayText is a string, we’ll tell Glue that we intend to use it as an integer.

To do this:

  1. Expand ScoreHud’s Objects in Glue
  2. Drag+drop the “Team1Score” onto the “Variables” item
  3. Select “DisplayText” as the variable
  4. Set the “Alternative Name” to “Score1”
  5. Set the “Variable Type” to int
  6. Click OK


Repeat the steps above, but this time use Team2Score, and create a variable called “Score2”.

Updating the HUD

Now that the ScoreHud can react to score changes, the ReactToNewScore can be modified to update the HUD. To do this, modify the ReactToNewScore method in GameScreen as follows:

If we run the game now we’ll notice that scores start out at 0 and increments whenever a player scores a goal.


Well, that was easy! Now we have scoring working. At this point we could call the game done. The next tutorial will be adding some extra finishing touches to the controls to make it more competitive and make the game play deeper.

<- Scoring HUDAdding Dashing ->