Flow of control question

BlitzMax Forums/BlitzMax Beginners Area/Flow of control question

DannyD(Posted 2005) [#1]


I have the above piece of code.I want the test program to be exited by pressing escape.I then want the program to:
draw a box
wait 2 seconds
draw another box
wait 2 seconds
more commands...

What seems to be the problem with my code as the second box only flashes briefly and pressing escape only works when the second box flashed on screen? Am I missing something about the sequential flow of control ? Thanks in advance.


Dreamora(Posted 2005) [#2]
if you are in the middle of the loop it will have to finish it before it can end as the "keyhit escape" check is only there.


DannyD(Posted 2005) [#3]
Ok but shouldn't it got like this
is esc pressed ?
y quit
n do command

It draws the first box no problem but doesn't do the second, how come ? The while loop should check at the start of each loop right ?


DannyD(Posted 2005) [#4]
If I put my commands into a function will this be a solution ?


Who was John Galt?(Posted 2005) [#5]
swap the last 2 lines before the wend


Dreamora(Posted 2005) [#6]
it will draw the first, wait 2 seconds then draw the second and wait again and then it will check if you pressed the key.

At the start you won't be able to press esc fast enough to prevent the first execution.

Yes while checks before execution, while repeat until checks after at least 1 execution.

Putting them into a function won't change anything as the execution order won't change.


DannyD(Posted 2005) [#7]
ahh yes, thank.


bradford6(Posted 2005) [#8]
Graphics 800,600

While Not KeyHit(KEY_ESCAPE) 'Escape 
	Cls
	SetColor 127,0,0
	DrawRect 200,200,800,100
	Flip
Wend

gametimer = 0
Repeat 
	Cls
	SetColor 200,10,10
	DrawRect 0,0,800,100
	Flip
	gametimer:+1
Until gametimer=200

End