Timer and Pollsystem()

BlitzMax Forums/BlitzMax Beginners Area/Timer and Pollsystem()

Volker(Posted 2008) [#1]
Can anyone explain to me, why using repeat/forever
doesn't make the timer work right (timerticks is always 0)
but while/wend works allright?
Adding pollsystem makes it work too.
Just wondering..

Local timer:TTimer = CreateTimer(10)
Repeat
'While(Not(KeyDown(KEY_ESCAPE)))
	'PollSystem()
	Print TimerTicks(timer)
'Wend
Forever



ImaginaryHuman(Posted 2008) [#2]
You have to poll the system in order to read the timer, I am figuring. The timer is managed by the o/s and so you have to `get events` from the o/s in order to get the timer value. Normally you'd have an event hook which processes the timer events, and some loop doing waitevent or something like pollsystem to continually read from the o/s.


Volker(Posted 2008) [#3]
Funny.
In the docs is for "timerticks" this as example given:

timer=CreateTimer( 10 )
Repeat
	Print "Ticks="+WaitTimer( timer )
Forever



grable(Posted 2008) [#4]
.


TomToad(Posted 2008) [#5]
As ImaginaryHuman said, you need to poll the system to get the timer ticks. In your Repeat/Forever loop, there is no polling of the system, but in your While/Wend loop, the KeyDown(KEY_ESCAPE) polls the system. that's why you get it to work with one and not the other.

if you replace the While(Not(KeyDown(KEY_ESCAPE))) with While True, you'll see that it's not updated then.


Volker(Posted 2008) [#6]
Ok, got it. Thanks.