Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Clock( ) in a loop

    Bug Reporting (FUZE 4 Nintendo Switch)
    6
    8
    387
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LinkCraft
      LinkCraft F last edited by

      For some reason having Clock( ) in a loop will crash fuze after like a min.

      1 Reply Last reply Reply Quote 3
      • pobtastic
        pobtastic F last edited by pobtastic

        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 a clear() or update() in your loop?

        1 Reply Last reply Reply Quote 0
        • D
          doumdoum F last edited by doumdoum

          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
          
          
          1 Reply Last reply Reply Quote 0
          • pianofire
            pianofire Fuze Team last edited by

            @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.

            Martin 1 Reply Last reply Reply Quote 3
            • Martin
              Martin Fuze Team @pianofire last edited by

              @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.

              1 Reply Last reply Reply Quote 1
              • pianofire
                pianofire Fuze Team last edited by pianofire

                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
                
                1 Reply Last reply Reply Quote 1
                • SteveZX81
                  SteveZX81 F last edited by

                  Thank you so much, this has caused me to rip my hair out today, I never would have guessed the solution at all.

                  1 Reply Last reply Reply Quote 2
                  • pianofire
                    pianofire Fuze Team last edited by

                    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
                    
                    1 Reply Last reply Reply Quote 3
                    • First post
                      Last post