Flow of control question
BlitzMax Forums/BlitzMax Beginners Area/Flow of control question
| ||
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. |
| ||
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. |
| ||
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 ? |
| ||
If I put my commands into a function will this be a solution ? |
| ||
swap the last 2 lines before the wend |
| ||
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. |
| ||
ahh yes, thank. |
| ||
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 |