GUIs creating problems with timers - SOLVED

Started by Akril15, Wed 01/11/2017 23:40:57

Previous topic - Next topic

Akril15

I've got several events in my game where I have timed sequences set up (not using AGS's timers, but ones including code like this):

Code: ags

function room_RepExec() {
if (timer<200) timer++;
if (timer==200) {
//timer expired!
//do stuff here
timer=0;
}
}


These timers work just fine, but I've just recently discovered that if I had my options GUI (just a normal GUI window) open when a particular timer ran out, the options GUI would close, the code meant to run after the timer ran out would try to run, but most of the animations wouldn't play and the game would hang, with the cursor perpetually stuck as the "wait" cursor. I thought this might be an issue with the game not being paused when the options GUI was open, but when I made sure that the game would pause while the options GUI was open (and unpause when it was closed, of course), the same problem occurred.

When I tried telling the game to only run the timer code when the options GUI wasn't visible, my problem was resolved, but it looks like I may have to go through my game and do the same thing to the Rep_exec section of every room that has one or more timers (and most likely add every other GUI which has the possibility of being open while the timers are running).

I would like to know if there is any tidier way of doing this, just in case this fix ends up being more trouble than it's worth.

Thanks in advance!

Cassiebsg

I have a suggestion (not a fix for the problem though)

Quote
thing to the Rep_exec section of every room that has one or more timers (and most likely add every other GUI which has the possibility of being open while the timers are running).

Either create a CloseGUIs() function, and then just call it at the start of your timer, or add a check to the If to not run if a GUI is open (however, if you need a GUI to be open when the code is running the first suggestion is better).
I find it weird that RepExec will still run if you have set the GUI to pause game, though.
There are those who believe that life here began out there...

Akril15

Looks like this wasn't as daunting an issue as I feared. Turns out I don't have nearly as many timers as I thought I did, and adding !IfGamePaused() to their "if" statements seemed to have fixed the problem.

Thanks for your help, Cassie.

SMF spam blocked by CleanTalk