peekevent + waittimer = ???

BlitzPlus Forums/BlitzPlus Programming/peekevent + waittimer = ???

First, I want a normal loop, for a normal game running on a canvas in a window that has a quit button and a quit prompt. And I want it to run no faster than 60fps. Waitevent waits a specific number of milliseconds regardless of how long the loop has been executing. How can I guarantee no faster than 60fps without a timer?

Second, Eikon, that solution seems to work in that example, but in a game-like environment it starts randomly quitting.

window = CreateWindow("WFT", 300, 300, 300, 300)
canvas = CreateCanvas(0,0,300,300,window)
timer = CreateTimer(60)

SetBuffer CanvasBuffer(canvas)

Repeat
	
	Color Rand(100,255),Rand(100,255),Rand(100,255)
	Line Rand(0,300),Rand(0,300),Rand(0,300),Rand(0,300)
	
	If MouseHit(1) Then Cls
	
	FlipCanvas canvas
	
	e = PeekEvent()
	WaitTimer timer
	
	If e=$4001
		If Confirm("Are you sure?  "+quitString$)
			quit=True
		EndIf
	EndIf

Until KeyDown(1) Or quit=True


You can click the mouse to clear the screen, I don't know if that's really effecting it or not.