Been starting to learn bmax and maxgui recently and came across waitevent and thought eewww. Did a forum search and came across this post about using timers for a game loop etc and thought i would post this bit of code here as it might help a few people.
If you dont want your game loop to process every timer tick but process as fast as possible when its got nothing else to do try this
Global GAME_WIDTH=320
Global GAME_HEIGHT=240
' create a centered window with client size GAME_WIDTH,GAME_HEIGHT
Local wx=(GadgetWidth(Desktop())-GAME_WIDTH)/2
Local wy=(GadgetHeight(Desktop())-GAME_HEIGHT)/2
Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,0,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
' create a canvas for our game
Local canvas:TGadget=CreateCanvas(0,0,320,240,window)
' create an update timer
CreateTimer 60
While True
If PeekEvent()
PollEvent()
Select EventID()
Case EVENT_TIMERTICK
RedrawGadget canvas
Case EVENT_GADGETPAINT
Local g=CanvasGraphics(canvas)
SetGraphics g
SetOrigin 160,120
SetLineWidth 5
Cls
Local t=MilliSecs()
DrawLine 0,0,120*Cos(t),120*Sin(t)
DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
Flip
Case EVENT_WINDOWCLOSE
FreeGadget canvas
End
Case EVENT_APPTERMINATE
End
End Select
EndIf
'Do other stuff in your loop here when no events in queue
Wend
This way you can keep redrawing at 60fps but dont have to wait around for that timer tick to process your game code(eg scripts/ai etc)
If im wrong, please shoot me down as im just starting to learn this stuff :)