Create a score that keeps its value between rooms

game score

Tutorial 18: Create a score that keeps its value between rooms

  1. Create an object called objVarPersist
  2. Add a Create event with this code:
    //create a global player score
    global.pscore = 0;
    
  3. Check the box Persistent
    persistent object in gamemaker
  4. Add this object to your first room. Do not add it to the second or additional rooms, as you only want to initiate the score once. It will retain its value across rooms even if you do not add it to those rooms.
  5. If you have already followed my previous tutorial on creating a score, remove the Create event from objScore. We no longer need it because we have created it on a persistent object in Step 1 above. This will retain its values across multiple rooms.

Go to a new room when score reaches a value

  1. On your player objects Step Step event change the if statement where you check the score to something like the following:
    if ((room!=Room2)&&(global.pscore==10)){
    
    //first check you are not already in Room2
    //and then when score reaches 10 go to room 2
    
    room_goto(Room2);
    
    }
  2. Remember to place your score object into the room.
  3. You might want to reset your score to zero on a re-start game button left click event.
Tomas
Latest posts by Tomas (see all)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top