how come this happens with timers

BlitzMax Forums/BlitzMax Beginners Area/how come this happens with timers

DREAM(Posted 2008) [#1]
timer:TTimer = CreateTimer(600) 

Repeat
	Print "Ticks=" + WaitTimer(timer) 
	If KeyHit(KEY_ESCAPE) Then End
	WaitTimer(timer) 
Forever


it just prints Ticks=1

everytime i thought it would be waiting 600 then print ticks=600


anyideas..?


TomToad(Posted 2008) [#2]
The parameter of Createtimer() is the number of times per second it cycles. So 600 will cause it to tick every 1.6666 milliseconds.
Waittimer() will wait until at least one tick was called and then return the number of ticks since the last time waittimer() was called.
you call Waittimer() at the end of the loop, then again at the beginning. Since there is most certainly less that 1.6666 milliseconds between the calls, the largest the number printed will be 1.
Try this.
timer:TTimer = CreateTimer(600) 

Repeat
	Print "Ticks=" + WaitTimer(timer) 
	If KeyHit(KEY_ESCAPE) Then End
	Delay(30) 
Forever

This will delay the program 30 milliseconds each loop, letting the timer tick off more than one time between each call. You'll notice that you will get at least 30 on each print.


GfK(Posted 2008) [#3]
Timer.Ticks() will tell you how many times a timer has ticked since it was created.

You can reset the counter with Timer._Ticks = 0