CreateTimer Fires When?

BlitzMax Forums/BlitzMax Programming/CreateTimer Fires When?

H&K(Posted 2006) [#1]
Function CreateTimer:TTimer( hertz#,event:TEvent=Null )

If I create two times to fire at 10Htz (say), then they will fire every 100Milli ,(Why BRL have bothered with Hertz when it just gets converted to number of milli wait is behond me, but anyway).

Every 100Milli Both timers emit, so if I want these two timers to fire at different points in a full cycle would I have to wait 50 Milli(say) before I create the second one? Would this garentee a maintaained 50 milli gap? (Assume I dont flood the event queue)

(If no one is sure, and just testing it I dont think you can be, because undocumented I dont want to rely on it)

Obviously if it cannot be garrenteed that there will be a 50milli gap between the two timers then Ill just make a single 50Milli timer and self select, but that ruins the symetry of My program


Dreamora(Posted 2006) [#2]
There is never a timing guarantee on a PC as any other program theoretically can "pause" your apps thread in exactly that moment where the "timing" would fire.

If you want / need that, there is only the way to simulate your own timing within your app which pauses when the app pauses etc.
This timing for example could depend on mainloop runs


H&K(Posted 2006) [#3]
SO you think I should just go for one Timer and then self select which one should have been fired?

I dont think the timer fire system is well thought out, because I would be quite happy to speedup and slowdown the two timers to maintain the gap, that is if windows grabbed loads of time I could overwatch the timers and increase/decrease the milli gap to reastablish the timming, but I just dont have the accesability to the timer object that I would need. (but I wouldnt know if this was BRL, or whatever event system it wraps)

All you seem to be able to do is stop it, and then recreate it. Oh, well, not a major problem, the program just looked nicer when the timers were independent. But thats more of an astetic problem


GfK(Posted 2006) [#4]
Why BRL have bothered with Hertz when it just gets converted to number of milli wait is behond me, but anyway
I'm confused. 'Hertz' is a unit of frequency meaning 'cycles per second' - which is exactly as the documentation describes it.

What part of the syntax are you having trouble with?

Regarding your other issue with offset timers - you could create one timer that fires once per second, and another timer that fires twice per second but ONLY triggers an event on every second tick (use 'timer.ticks() Mod 2' for this).


H&K(Posted 2006) [#5]
'Hertz' is a unit of frequency meaning 'cycles per second' - which is exactly as the documentation describes it


It gets translated internaly into milli gap, that is if I say 60Hrtz it doesnt fire at 60Hrtz, it fires at 1000/60 milli (16.66666666), which is different. (And dont go saying oh but, cos they are not the same)

http://www.blitzbasic.com/Community/posts.php?topic=59885#667937


Dreamora(Posted 2006) [#6]
Gfk: You are pointing out one problem there actually. cycles per second. Sounds good. But what if you want to fire it all 4 seconds? 0.25 does not work as it needs int, so having had its timelength in milliseconds as VB and other languages have it would make much more sense.
Did you ever try to create something like a "sleep functionality" that puts your app on pause after a given time ^^ with other languages you just wait on the timer to fire, with blitz you have to IF check every main loop run and even then you will most likely still miss the right ms ...


Warren(Posted 2006) [#7]
If I might market for a moment, my time/timer module has a very easy to use interface that is based in milliseconds.

http://www.pixelfist.com/


GfK(Posted 2006) [#8]
Gfk: You are pointing out one problem there actually. cycles per second. Sounds good. But what if you want to fire it all 4 seconds?
Use CreateTimer(1) and wait until timer.ticks() = 4.


Dreamora(Posted 2006) [#9]
Great ... so I need again IF checks instead of just have an event fired at some point ...

And what it if shall fire after 20 minutes? I think you might miss the point that the current timer is only for games, not for applications. An application that needs a < 1s timer isn't a that "normal" thing. But an application that has timers for autosave etc is quite regular.


Waren: Nice idea, but if I need an Update method I can use an own Timer Type and simply check millisecs() - starttime > ticktime. And I would definitely not pay for something like that.


Fabian.(Posted 2006) [#10]
Use CreateTimer(1) and wait until timer.ticks() = 4.
Why not simply use CreateTimer(0.25)?? it does exactly the same


H&K(Posted 2006) [#11]
Use CreateTimer(1) and wait until timer.ticks() = 4.
Really, Id just use CreateTimer (0.25)

EDIT: hahahah, didnt copy honest.

As I said at length in th other thread it goes 1000/hertz, so 4000 delay, my point being why not just let me go 4000 and avoid rounding errors and stuff


Dreamora(Posted 2006) [#12]
Urgs you are right.

I was quite sure that CreateTimer wanted Int in a previous version where I was trying to do something like this but either it changed or I was bogus.