Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Hubert BAYRE
7
Years of Service
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 24th Jan 2018 19:32 Edited at: 24th Jan 2018 19:34
Hello.
I already use the Timer() command into my code. but i use ResetTimer() somewhere. Now i need another timer not affected by the ResetTimer() !

So how to code my own timer function (seconds)?

Many thanks.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 24th Jan 2018 20:41
you could use the fps

life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 24th Jan 2018 21:32 Edited at: 24th Jan 2018 21:33
I would just add the GetFrameTime() to a variable once per loop




At any time you can zero any of the timers (Eg... Timer2# = 0) and they will continue counting from zero again.

Alternatively: you can calculate the difference between the Timer() and a previous value of Timer() and add that to your own timer variables (Timer1#, Timer2# etc...) in every loop.
Hubert BAYRE
7
Years of Service
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 24th Jan 2018 23:26
Perfect !
Many thanks.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jan 2018 09:06
Quote: "Alternatively: you can calculate the difference between the Timer() and a previous value of Timer() and add that to your own timer variables (Timer1#, Timer2# etc...) in every loop."


Use this one. GetFrameTime() will not be as accurate, there will be a slight variance every game cycle which will add up to a bigger variance over time.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 25th Jan 2018 09:24 Edited at: 25th Jan 2018 09:42
Quote: "Use this one. GetFrameTime() will not be as accurate, there will be a slight variance every game cycle which will add up to a bigger variance over time."


Not actually true in my experience. There isnt a slight variation every cycle if your FPS is above 5FPS. Try it...compare the two.

...I have, and there was no variance over 30 minutes of running time. The only reason to use the Timer() is that GetFrameTime() gives a maximum of 0.2 seconds. If your frame rate did drop below 5FPS (>0.2 frame time) then there could be a difference between the values that would be given by the two methods but thats only if the frame rate drops that low.

Otherwise 2 timers using the two different methods keep time perfectly together. Either way...for most purposes they both work fine.

I guess if you want the most accurate in all situations then using the Timer() - PreviousTimerValue method works in all scenarios so is better I guess.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jan 2018 14:03

Quote: "Otherwise 2 timers using the two different methods keep time perfectly together."


I tried it out of curiosity (not to prove anyone wrong!)
In the example below I just grabbed some old code to create a load. By 80 seconds, it was starting to drift slightly. By 130 seconds it was drifting by 0.01 seconds every 10 seconds or so.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 25th Jan 2018 21:39
You are absolutely right and I was wrong! I couldn't see any Timer code drift at all but I windowed it (instead of fullscreen) and you can get large differences after a while - especially with other apps running. The GetFrameTime() stops completely when you drag a window where as Timer()-TimerPrevious keeps time no matter what. Theres not a lot of difference but its there!

Thanks for the clarification.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 26th Jan 2018 09:44 Edited at: 26th Jan 2018 09:45
Quote: "So how to code my own timer function (seconds)?"


A simple solution for mutiple timers https://forum.thegamecreators.com/thread/219869
Hubert BAYRE
7
Years of Service
User Offline
Joined: 21st Oct 2017
Location: France
Posted: 26th Jan 2018 22:00
Very interesting thanks.
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 27th Jan 2018 00:16 Edited at: 27th Jan 2018 00:25
I just make a variable to use for a timer, then subtract that from the timer() to get the elapsed time.

Resetting the timer is as easy as setting it the first time.



Of course, that could be a float (temp_time#) is you want fractions of a second instead of whole numbers. (whole numbers > 2 is 3 seconds, where float >3 is 3 seconds)

You can have as many as you want, and reset any of them at any time, but you never have to reset the main Timer() with this method.

You just reset each timer by assigning it a value = to the main Timer() to start the count over for subtracting it again from the main Timer() for elapsed time.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-23 00:48:17
Your offset time is: 2024-11-23 00:48:17