Legacy GM [SOLVED] add a life by reaching a certain score?

B

Bhreno

Guest
I am currently using this code to do this (in step event obj_game):
Code:
// "total_score" is a var of the total score;
// "score_live" is the var of the score needed to make a live;
// "lives" is the var of the lives;

if (total_score > score_live * 1000)
     {
          score_live = score_live + 1;
          lives = lives + 1;
     }
The problem is that every time I move to the next level, this code ends up being counted again from the beginning and life ends up multiplying from room to room.

In game start code (in obj_game):
Code:
score_live = 1;
lives = 5;
How do I solve this?
Note: The object in question that houses the code cannot be persistent!
 
H

Homunculus

Guest
If the object can't be persistent, make the variable score_live global. Or recompute score_live from the total score at room start:

Code:
score_live = ceil(total_score / 1000);
 
B

Bhreno

Guest
Did not work. The lives continues to multiply as the score_live increases by "+1".

how it should be:
score_live = 1; lives += 1;
score_live = 2; lives += 1;
score_live = 3; lives += 1;
score_live = 4; lives += 1;

how is it happening:
score_live = 1; lives += 1;
score_live = 2; lives += 2;
score_live = 3; lives += 3;
score_live = 4; lives += 4;
 
H

Homunculus

Guest
I'm afraid you will need to be a bit more specific on what you are doing and where. I don't see any reason for the score to be reset from room to room with just the code you posted. In fact, I don't even know how you are keeping the total score from one room to the other if obj_game is not persistent and the variable is not global.
 
B

Bhreno

Guest
It worked!
The problem was the value of live_score = 1, which was being assigned when creating obj_game, but it should be in game_start, counting only once during gameplay, not whenever obj_game is created at the beginning of levels.
 
B

Bhreno

Guest
I'm afraid you will need to be a bit more specific on what you are doing and where. I don't see any reason for the score to be reset from room to room with just the code you posted. In fact, I don't even know how you are keeping the total score from one room to the other if obj_game is not persistent and the variable is not global.
I posted only the codes I thought I could use, but there are many others haha And the var "total_score" is global.
 
Top