• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Problem with lives in game[Solved]

Z

zimice15

Guest
Hi,
I am new to gamemaker .I am making a remake of Asteroids .I have problem with lives. I want lives and when player has 100 points add another live but stop after one added and after player reachs 200 points add another live.Here is a code:
var LoopCount
for (LoopCount = 0; LoopCount < global.life; LoopCount++)
{
draw_sprite(spr_playerlive, 0, 36 * (LoopCount + 1) , 76);
}
if(global.points >100){
global.life += 1;
}
 

DarthTenebris

Definitely not a Sith Lord
Hi and welcome to the forums!

First of all, I would suggest using the [ CODE ] and [ /CODE ] tags (remove spaces) to clean your code up. It will be easier to read by other people, hopefully increasing your chance of getting help.

To your problem:
You can adjust the criteria for earning a life as you go. Here's how:
Code:
need = 100;
if (global.points >= need) {
     //global.points = 0;     **this bit is optional, if you want to make it harder remove this comment.
     global.life++;
     need += 100;
}
The above code will give the player a life when the player reaches 100 points. Then it will update the criteria to 200, making the player need 100 more points to get another life, basically giving the player a life every 100 points. An optional piece of code can be added to make it progressively harder to get lives. Feel free to ask if you don't understand :)

Hope I helped :)
 
Z

zimice15

Guest
Hi and welcome to the forums!

First of all, I would suggest using the [ CODE ] and [ /CODE ] tags (remove spaces) to clean your code up. It will be easier to read by other people, hopefully increasing your chance of getting help.

To your problem:
You can adjust the criteria for earning a life as you go. Here's how:
Code:
need = 100;
if (global.points >= need) {
     //global.points = 0;     **this bit is optional, if you want to make it harder remove this comment.
     global.life++;
     need += 100;
}
The above code will give the player a life when the player reaches 100 points. Then it will update the criteria to 200, making the player need 100 more points to get another life, basically giving the player a life every 100 points. An optional piece of code can be added to make it progressively harder to get lives. Feel free to ask if you don't understand :)

Hope I helped :)
So I tried to copy this code to my draw event .When i write: global.points=0; it works and reset score but every 100 points it add a life.It wont wait for 200 points.When I make comment (//global.points=0;) it starts adding lifes and don't stop.Btw thanks for tips i try next tike use CODE tags.
 

DarthTenebris

Definitely not a Sith Lord
So I tried to copy this code to my draw event .When i write: global.points=0; it works and reset score but every 100 points it add a life.It wont wait for 200 points.When I make comment (//global.points=0;) it starts adding lifes and don't stop.Btw thanks for tips i try next tike use CODE tags.
Why do you need it in the draw event? I thought you'd place this bit of code in the step event - which I think is where it is actually supposed to go. Generally don't use the draw event for stuff that doesn't need drawing (for example your movement code).

As for your issue, are you sure there is no other code that messes up with this bit of code? Logically thinking I'd say that is supposed to work - up to the logic at least. You can try to solve the code conflict, or you can try to adapt the logic and write your own code.

Hope I helped :)
 
Z

zimice15

Guest
Why do you need it in the draw event? I thought you'd place this bit of code in the step event - which I think is where it is actually supposed to go. Generally don't use the draw event for stuff that doesn't need drawing (for example your movement code).

As for your issue, are you sure there is no other code that messes up with this bit of code? Logically thinking I'd say that is supposed to work - up to the logic at least. You can try to solve the code conflict, or you can try to adapt the logic and write your own code.

Hope I helped :)
Ok I'ill try to fix it. You helped so much. Thanks :)
 
Last edited by a moderator:
The problem your having is it keeps resetting the score needed to 100 before the check. You need to put the "need=100" in the create event and it should be fine.
 

DarthTenebris

Definitely not a Sith Lord
The problem your having is it keeps resetting the score needed to 100 before the check. You need to put the "need=100" in the create event and it should be fine.
Thank you for correcting me! :) " need=100; " indeed should be in the create event :p
Now I feel silly :p
 
Top