Beginner's guide to Construct 3

1946

Index

Features on these Courses

Contributors

Stats

1,331,242 visits, 3,853,674 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 20 Sep, 2017. Last updated 24 Jun, 2024

Keeping score

Let's have a score so the player knows how well they've done. We'll need another variable for this. You might think "lets put the score as one of the player's instance variables!". That's not a bad first idea, but remember the value is stored "in" the object. If there are no instances, there are no variables either! So if we destroy the player, we can no longer tell what their score was, because it was destroyed with the player.

Instead, we can use a global variable. Like an instance variable, a global variable (or just "global") can store text or a number. Each variable can store a single number or a single piece of text. Global variables are also available to the entire project across all layouts - convenient if we were to add other levels.

Right-click the space at the bottom of the event sheet, and select Add global variable.

Adding a global variable

Enter Score as the name. The other field defaults are OK, it'll make it a number starting at 0.

Adding a Score global variable

Now the global variable appears as a line in the event sheet. It's in this event sheet, but it can be accessed from any event sheet in any layout.

The 'Score' global variable

Let's give the player a point for eliminating a goblin. In our "Goblin: health less or equal 0" event, click Add action, and select SystemAdd to (under Global & local variables), and choose Score with a value of 1. Now the event should look like this:

Event adding to score

Now the player has a score, which increases by 1 for every goblin they remove - but they can't see their score! Let's show it to them with a text object.

Disabled Comments have been disabled by the owner.