SOLVED How do i keep the score from the previous room and put it in the next room?

B

Brody_PlaysYT

Guest
As the title suggest i am wondering how to keep the score from the previous room and put it in the next room
if someone could tell me what i need to do it would be greatly appreciated as it would be my first time trying to make a highscore system so help would be greatly appreciated
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
In order for a variable to persist through room transitions, it must be declared under global scope or be an instance variable of a persistent instance.
Since this is about score, though, you can as well use the built-in variable score, which is global by default.

It's also important to note that variables can appear to not persist throughout room transitions if anything in your target room resets the variable in question, so make sure that you don't have anything like this in places you don't want it to be in - you may want to reset the score when starting a new game, but not when moving to the next stage.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Hello! Please don't share projects like this as most people don't have the time or inclination to download someone else's project and look through it to solve the problem they are having. And if we did do that and edited the file, what would you learn? The best thing is to always post the relevant code and show us what you've tried, then we can explain how you can fix the code, and you'll learn more from it. ;)

That said, in your case from what you say I would suggest simply using a global variable. When the game starts you set it to 0, then you can increment it throughout the game and all instances can access it and the value will be carried from room to room.

 
B

Brody_PlaysYT

Guest
ok thanks i just found the problem it was because i had two o_game objects in use out of all the rooms i have which i can only have one otherwise it resets the score variable to 0 in the next room it is in

im actually going to upload it to github instead so its easier to see the code without downloading it
 

TsukaYuriko

☄️
Forum Staff
Moderator
That's beside the point. We'd still have to sift through your project and find whatever code it is that you're talking about on our own, which leads to the same result - most likely, nobody will bother as we are all doing this in our spare time and aren't getting paid for it. Linking to a code dump is more likely to lead to your topic being ignored than anything else.

So, for future reference, you can increase your chances of receiving help tremendously by simply citing the code that's relevant to your issue. ;)
 
B

Brody_PlaysYT

Guest
lemme quickly find the code

this is my o_game draw gui code

GML:
if paused_ {
    var gui_width = display_get_gui_width();
    var gui_height = display_get_gui_height();
    draw_set_color(c_black);
    draw_rectangle(0, 0, gui_width, gui_height, false);
    draw_set_color(c_white);
    draw_set_halign(fa_center);
    draw_set_valign(fa_middle);
    draw_text(gui_width/2, gui_height/2, "Paused Press R to Restart");
}

draw_set_halign(fa_right);
draw_text(display_get_gui_width()-6, 4, "Score: " + string(score));
draw_set_halign(fa_left);
 

TsukaYuriko

☄️
Forum Staff
Moderator
This is a forum, not a chat. Please keep the amount of sequential replies in a topic at a maximum of 1. ;)

That aside, didn't you say you found the problem? I'm a bit unsure about what the remaining issue is... is the score still resetting, or what's the new issue?
 
Top