Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loops can freeze unexpectedly.
#1
Windows has a strange problem with loops.

 If you don't leave Windows time to do background processes, it can sometimes freeze the computer.

 This is not the first compiler to give me this problem, and I don't know why it took so long to figure it out.



Code:
' Test


  set redraw off

 cnt = 0
 set color 255,255,255
 cls
 set color 0,0,0
 set caret 100,100
 wln " Loop test"
 wln
 wln " Hit escape key to exit "
 redraw
   
     do  
         m3 = inkey(0)
         if m3 = 27  
            wln " This loop will not work if you leave out the wait 10 statement "
            wln " It needs at least a wait 0 "
            break
         endif
        'wait 0
        wait 10
     loop
   
redraw
wait 3000
Reply
#2
Yes, when you call 'wait' naalaa takes care of all waiting events for the window. But a value of 0 should work?
Reply
#3
(05-15-2020, 03:44 PM)Marcus Wrote: Yes, when you call 'wait' naalaa takes care of all waiting events for the window. But a value of 0 should work?

 In the above program, this works on my Computer:

do
m3 = inkey(0)
if m3 = 27
wln " This loop will not work if you leave out the wait 10 statement "

wln " It needs at least a wait 0 "

break

endif

wait 0


loop


 This does not work:

do
m3 = inkey(0)
if m3 = 27
wln " This loop will not work if you leave out the wait 10 statement "

wln " It needs at least a wait 0 "

break

endif

 

loop
Reply
#4
That can be good to know! I believe I buried a note about it somewhere in the docs, but it don't think it's explained in any of the examples Smile

If you use the Speed library, for fixed fps, it will do the sleeping for you when you call SPD_HoldFrame(fps_value), so no need to call wait there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)