• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Global clock issues

T

Theghost

Guest
Hy there,
I am working on a new game. And you know what that means right? New obstacles!

I've encountered a problem that my clock doesn't get updated when the rooms change.
Let me further explain: I have a clock in my one of my rooms. it updates every second when I am in the room. I also have a computer in my room. when I get on the computer and get back to my original room the clock doesn't update. as in it stays the same no matter the amount of time inside the computer (which is a different room).

Global variables and global object (as the same object in every room) don't seem to work.

can someone please help me?

Thnx
 
B

BeepBoop

Guest
What do you mean "global object"? Is it flagged as "Persistent"?
 
T

Theghost

Guest
What do you mean "global object"? Is it flagged as "Persistent"?
I mean an object which is in every room of the game. And the object being persistent doesn't help either. I tried.
 

FrostyCat

Redemption Seeker
Post every piece of code in that object and state the event where each comes from. It's foolish to assume there's only one way to do things wrong.
Don't: Paraphrase code without citing the original

A lot can go wrong from intuition to keyboard, especially if you are a novice in GML. If you want to summarize your code, fine, but make sure the original code is available via a code tag or link so that your assumptions can be cross-checked. You aren't making it any easier by making responders guess at your code.
 
Last edited:
T

Theghost

Guest
So this is al the code in my timer object. It is fairly simple and probably not optimized.

Code:
// create event
timer = 0;                 
realisticTimerM = 0;       //actual displayed time in minutes
realisticTimerH = 8;       //actual displayed time in hours (starts at 8 am)
ME = "a.m.";

//step event
timer +=1;
if(timer == 60)
{
    timer =0;
    realisticTimerM += 1;
}
if(realisticTimerM == 60)
{
    realisticTimerH += 1;
    realisticTimerM = 0;
}
if(realisticTimerH >= 12)
{
    ME = "p.m." ;                      //if it is afternoon it changes from am to pm
}

//draw event
if(room =room_office)    //my room with the timer
{
    draw_sprite(spr_timer,0,5,15) ;                 //drawing of the clock
    draw_set_font(font_timer);
    draw_sprite(spr_timer,0,5,15)                   //very unoptimized code (will change later)
    draw_set_font(font_timer);
    draw_text_transformed(30,30,realisticTimerH,3,3,0);
    draw_text_transformed(90,30,":",3,3,0);
    draw_text_transformed(110,30,realisticTimerM,3,3,0);
    draw_text_transformed(175,30,AM,3,3,0);
}
 

Lady Glitch

Member
Your object resets the timer each time you change rooms. Here is why:
Code:
// create event
timer = 0;                 
realisticTimerM = 0;       //actual displayed time in minutes
realisticTimerH = 8;       //actual displayed time in hours (starts at 8 am)
To fix it, remove it from every single room and create a new blank room. Put your object in there and drag your newly created room on top of the other rooms. Make the object persistent and add this in its Create Event:
Code:
room_goto_next();
 
Top