Game Maker Studio Score, My Score resets when going to the next room

3.5k views Asked by At

I'm having a problem regarding the scores in my game, My game is about answering questions using jumbled letters and when the player gets one correct answer, the game should add +1 to the game score and move to the next level (which is in the next room) and will generate another question, and keeping your last score which is 1. My problem is, the score just keeps on resetting to a value of 0 when moved into the next room. I want it to continuously add +1 even when I go to the next rooms. Thankyou in advance.

2

There are 2 answers

0
German Gorodnev On

There are many solutions.
1) Set your score controller object as persistent
persistent
This is the best, as you don't need to do anything else, and in fact, it's a good rule to have one object as a persistent controller.

2) You can save your score to the file and load it each time this object (that stores the variable) is being created
This requires save\load manipulation, and in some cases (e.g you don't want to have ANY persistent objects) can be better, but I highly doubt.

0
klys On

You are not giving enough details about how are you storing the score value.

That may be cause by many issue in the way you are making the game, so im going to try to give all solutions to all possible scenarios:

1) Storing Score in Object Variable

This way may have two different sub scenarios:

a) Going to Next Room after Right answer

b) Restart the same room

This completly reset the variable on the object because the object is destroyed and then created again initilizing again the variables it hold when the room is created.

For this the solution is simply: set persistent true, you can do it from the form object properties (the interface that pop up when you open a object) or using gml on the create event of the object:

object: CREATE event

persistent = true;

This will make the object even if is repeated on the room created to no to create it again, so the event CREATE will no be never repeated again.

2) Storing the Score in variable of the room using Room Creation Event

In this scenario happeng the same that above, its just a local variable the room but exists only for the room and will only exists during the room until its restarted or leaved.

In this case the best is to transform this variable to a global instance in the following way:

global.points = 0;

And this is the best way to store score for you game.

Just remember no to put it in a create event of a not persistent object or it will be reseted to ZERO everything that object is created.

In that case you can check if the variable exists and then if not initializing it:

if (variable_global_exists("points") == true) {
    global.points = 0;
}

Now if you want to save it you need to use file functions which is another question.