Clock( ) in a loop
-
For some reason having Clock( ) in a loop will crash fuze after like a min.
-
Please can you provide example code? I've just tried this and it works fine for me;
elapsed = time() loop clear() printAt( 0, 0, clock() ) printAt( 0, 2, "Elapsed = ", int( time() - elapsed), " seconds" ) update() repeat
5 minutes and counting! It may be unrelated to
clock()
more likely from not having aclear()
orupdate()
in your loop? -
This code crashes Fuze after 2 minutes.
Maybe Clock() and Controls() are not compatible.
It's OK if you comment one of these functions (inside the loop).cl = Clock() ctrl = Controls(0) Loop Clear() cl = Clock() ctrl = Controls(0) PrintAt( 10, 10, "wait 2 minutes" ) Update() Repeat
-
@doumdoum I have confirmed this one and raised an issue. Interestingly if you remove the first two lines (which will make the variables local to the loop and not global) the problem does not occur.
-
@pianofire said in Clock( ) in a loop:
Interestingly if you remove the first two lines (which will make the variables local to the loop and not global) the problem does not occur.
That info's pure gold. I would have instantly assumed this of a function but not necessarily considered the scope inside of a loop. That might help elsewhere too.
-
If your are using this sort of code to debounce your button presses:
oldc = controls(0) loop clear() c = controls(0) if c.a and !oldc.a then print("hello") endif update() oldc = c repeat
You will have this problem. here is a work around until it is patched:
oldc = [ .a = 0, .b = 0 ] loop clear() c = controls(0) if c.a and !oldc.a then print("hello") endif update() oldc = [ .a = c.a, .b = c.b ] repeat
-
Thank you so much, this has caused me to rip my hair out today, I never would have guessed the solution at all.
-
So my latest finding on this problem is that this seems to work fine:
oldc = controls(0) loop play() repeat function play() clear() c = controls(0) if c.a and !oldc.a then print("hello") endif update() oldc = c return void