sonicforvergame wrote:say where to put the code
You won't learn if I do all your coding for you. This is pretty simple, and when you get it, should help you a lot in the future. Also, you shouldn't ever need to be told where code should go. If you know what the code does, then you should know where a good place to put it is. Do you know what that code does?
sonicforvergame wrote:Euhhh didn't work can you be more specified like :
That isn't very specific either. It is helpful if you tell us how things don't work. Due to errors, or the game does nothing?
Anyway, you can think of a variable as a piece of paper. When you create the paper (creating a variable) you give it a name. That way you can find it whenever you need it. On this sheet of paper you have something written on it. Normally you'll be dealing with integer variables, so a number is written on it. In your game, you'll have many of these papers.
Now in your case you wanted to be able to keep track of the number of lives the player has. So, you need to create an integer variable (sheet of paper) called lives. By default the paper says 0. We though want to set the number of lives to 3, so in the view's create actor, we use the following code.
- Code: Select all
lives = 3;
With that, the game erases the number that was on the sheet, and replaces it with the number 3. Now whenever we want to check how many lives the player has, the paper will have 3 written on it.
From there, we can use lives exactly as you think they should be used. When the player dies, you reduce it by one. Right after reducing it by one, we want to check if the player still has lives. If they do, restart the level, otherwise don't do anything. Does that make sense?