How would you create a timer or an alarm

BlitzMax Forums/BlitzMax Beginners Area/How would you create a timer or an alarm

Barbapapa(Posted 2007) [#1]
I wanted to create some sort of timer or alarm so I can call an action every x time. I wanted the time to change randomly. I succeeded by using the builtin Timer and encapsulated it in a type. Is this ok, or is there another , better way?

Something like this but not yet finished as not completely in a type yet.

Type TMyTimer
	
	Field newTimer:TTimer
	
	Method createMyTimer(_hertz:Int) 
		If newTimer Then StopTimer(newTimer) 
		newTimer = CreateTimer(_hertz) 
	End Method

		
	Method myTimer:Int() 
		Delay 1
		PollEvent()
		If EventID() = EVENT_TIMERTICK
			Print "Tick: ..............................................."
			Return True
		EndIf
	End Method

End Type



Beaker(Posted 2007) [#2]
Does this help:
Interval System


Barbapapa(Posted 2007) [#3]
Hey this is cool, had a long search before but didn't find anything, probably the wrong search criteria.

So you use the built in timer, too, this is good to know. And yours is much more sophisticated (I didn't succeed with the list). You didn't use <b>PollEvent</b>, but use a Hook instead, could you explain me a little bit on this behalf?