Okay, first thing to know, you shouldn't use textNumber like that. I know that is how it is used in the caveman ged, but using it like that has has been known to create problems. So instead you should create your own variable for lives and your own variable for score. To do add the this script to global code (note if your text display actors have the names score and lives you'll need to destroy the actors, or choose different names for the variables). Just to make sure, you can go to global code by clicking the [Global Code] button.
Global Code
- Code: Select all
int score; // creates a variable called score
int lives; // creates a variable called lives
When you add that script, give the script a name, and click [Add]. Now you have two variables, one for score and one for lives.
Whenever you want to increase score, you do this (same idea as what you were using before, but it uses a real variable that you can rely on).
- Code: Select all
score = score + 1;
And one thing you have to add to actually make the score display is the following.
score_actor -> Draw Actor -> Script Editor
- Code: Select all
textNumber = score; // this will display the score
Now for lives it will work exactly the same way. But, since you want to start with a certain number of lives, you can add this to the player's create actor event.
- Code: Select all
lives = 3; // this sets the player's life to 3
And just to reiterate, when you want to reduce the player's life, you use this.
- Code: Select all
lives = lives-1;
And to have it displayed, use this.
lives_actor -> Draw Actor -> Script Editor
- Code: Select all
textNumber=lives;