Timers for an Event

Hi all

im really struggling with timers for random events and was wondering if someone could help me please,

i have the random bit sorted and know it works as iv done it before for other events the only thing is the timer for this event will have a timer counting down from 1 hour so i want it to be displayed like this 1h 0m 0s so heres what i got as basic i just dont understand how to convert it, i know i will have to convert the variable but does that mean i will have to have 3 different text box’s to display the timer or could i add the variables together.

Sooooo… i read back my own post and thought id answered my own question so here is what i have now and it just seems to zero the Timer but i have the layout i want :slight_smile: anyway can someone please try tell me why my timer zeros as everything i see should work

I can’t test it now, but the time should be stopped at 0:59:59 :confused: … You should move the event 128 as sub-event of 127, other way the event 127 reset the timer and 128 doesn’t run :slight_smile:

Anyway, it’s a strange way to have a timer as you already have the info you need in one timer, you should find a form to formatting seconds in hh:mm:ss. Again, I can’t test it (or do anything to GD related) now, but let’s theorize :smiley:
You have a timer that returns the time elapsed in seconds, you just need to “format” it. To get the minutes from the time t in seconds, do t/60 and floor the value (2,65 minutes are 2 minutes and some seconds). Now you needs the hours, you have to do t/3600 to convert seconds to hours.
Now wait, you have to subtract the minutes to seconds (or 65 seconds will be = 0h 1m 65s), and you have to substract the hours to minutes too (or 3600 seconds will be = 1h 60m 0s), in the right order, it’s:

t >> Get hours >> Get minutes (subtracting hours converted to minutes) >> Get seconds (subtracting minutes and hours converted to seconds)

t h = floor(t/3600) m = floor(t/60) - h*60 s = t - m*60 - h*3600

I don’t know if you get the theory, or if you are interested at all, so let’s do it in a practical way now.
You need only one timer or some way get the time, I’ll assume the variable t has the time in seconds to format (t can be a float, so TimeDelta() will works here):

Do = floor(Variable(t) / 3600) to the variable h Do = floor(Variable(t) / 60) - Variable(h)*60 to the variable m Do = floor(Variable(t)) - Variable(m)*60 - Variable(h)*3600 to the variable s Do = VariableString(h)+"h "+VariableString(m)+"m "+VariableString(s)+"s" to the text of EventTimer

Finally, I think it can be done in just one line, but it’s ugly, hard to read, and maybe with poor performance:

Do = ToString(floor(Variable(t)/3600))+"h "+ToString(floor(Variable(t)/60)-floor(Variable(t)/3600)*60)+"m "+ToString(floor(Variable(t))-floor(Variable(t)/60)*60)+"s" to the text of EventTimer

Not so cool! :laughing:

1 Like

thanks ill have a fiddle and let you know how i get on and yea i understand what ur saying just couldnt get my head rnd how to code it

The two last “codes” are written in the GD syntax, you just need the time to format in a variable “t” (in seconds) :wink:

Cheers lizard got it sorted now :wink:

Do = ToString(floor(Variable(t)/3600))+"h "+ToString(floor(Variable(t)/60)-floor(Variable(t)/3600)*60)+"m "+ToString(floor(Variable(t))-floor(Variable(t)/60)*60)+“s” to the text of EventTimer

Sorry, how would that one line continue with adding milliseconds? Can someone please solve this?