Need help here
BlitzMax Forums/BlitzMax Beginners Area/Need help here
| ||
Here my problem I want each 3 second to call my function but something wrong because it goes to another loop for the event, event if I put my IF into the second loop it's not working if someone can help my out understanding this issue thanks. SuperStrict Import maxgui.drivers Local MyWindow:TGadget=CreateWindow("test", 200,200,320,240) Local update:Int = MilliSecs() Repeat If MilliSecs() > update+3000 Then myfunction() update = MilliSecs() End If While WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MOUSEDOWN End Select Wend Forever Function myfunction() Print "each 3 second" End Function |
| ||
Your program is using an event loop (calling WaitEvent). This means it is well behaved and spends most of its time asleep inside the WaitEvent command. You should use CreateTimer and EVENT_TIMERTICK to do what you are trying to do. If you want your program to busy loop (use 100% CPU) so you can check the MilliSecs() function repeatedly you will need to change the While WaitEvent...Wend loop to If PollEvent...EndIf. Last edited 2011 |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?code=1721 |
| ||
SuperStrict Import maxgui.drivers Local MyWindow:TGadget=CreateWindow("test", 200,200,320,240) Local update:Int = MilliSecs() CreateTimer 60 While WaitEvent() Select EventID() Case EVENT_TIMERTICK If MilliSecs() > update+3000 Then myfunction() update = MilliSecs() End If Case EVENT_WINDOWCLOSE End Case EVENT_MOUSEDOWN End Select Wend .... |
| ||
thanks guys, work pretty well |