i need help


i am making a game where you can collect coins, and i have written a score system for it, but if you change rooms, the score is back to zero, how can you save the score? here the code:

collision with the player in the coin object
//+ Score
global.coin_score += 1;
audio_play_sound(snCoinPickup, 10, false);

the score object
//the score
global.coin_score = 0;

it would be nice if you guys can help me out with that


You don't save the score, you just leave it alone. Having a "score object" in every room to poke it is NOT leaving it alone.

Check the "Persistent" box in the Object Properties window for your score object, then remove all instances of it from every room except the first room.


ok that works, thank you, but its like, i have a menu, when i press start and go to the first room, get a coin and go to the next room it works, but, if i go to the menu and back to the game, its zero again, and i also have a shop, where you can buy stuff, there its also zero, is there a way, to save the whole score?


You need to make sure your Score object is persistent. Make a room at the very start of your game and put the Score object in there. In the Score object's create event, set global.coin_score to 0. In the Room Start event of the Score object, put room_goto_next(). You don't need to do things this way, but this way ensures all your global variables have a way of being defined once at the very start of the game.

When you make a main menu eventually (you know, when the player selects 'New Game' to actually play your game), which should be one of the rooms immediately after your loader room in the room order, when the player selects 'New Game' or whatever, be sure to set global.coin_score to 0 there. Don't set global.coin_score to 0 anywhere else except in those two situations.

Go trhough your project and make sure the Score object does not exist in any room except the loader room. Make sure the Score object is not being created via instance_create() anywhere in your project.


that didnt worked, or i didnt understand it, i made a room, befor all my other rooms, and put in there what you said, but i didnt started