Timer and Pollsystem()
BlitzMax Forums/BlitzMax Beginners Area/Timer and Pollsystem()
| ||
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 |
| ||
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. |
| ||
Funny. In the docs is for "timerticks" this as example given: timer=CreateTimer( 10 ) Repeat Print "Ticks="+WaitTimer( timer ) Forever |
| ||
. |
| ||
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. |
| ||
Ok, got it. Thanks. |