Navigation

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

    Unexpected behaviour with sprite user vars

    Bug Reporting (FUZE 4 Nintendo Switch)
    5
    7
    313
    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.
    • pobtastic
      pobtastic F last edited by

      Run it first with the lines commented, you see what you'd expect "0.000000" x 2.

      spr = createSprite()
      spr.pos = {}
      
      loop
        clear()
      
        printAt( 0, 0, spr.pos.x )
        printAt( 0, 1, spr.pos[0] )
      
      // This line causes an "Invalid variable access".
      //  spr.pos.x += 1
      
      // This line causes a hard crash!
      //  spr.pos[0] += 1
      
        update()
      repeat
      

      If we change the initialisation to;

      spr = [
        .pos = {}
      ]
      

      ...then it works just fine as expected!

      1 Reply Last reply Reply Quote 1
      • vinicity
        vinicity F last edited by

        I didn’t know you could assign an empty vector?

        Does it work if you do spr.pos = {0, 0, 0} instead?

        1 Reply Last reply Reply Quote 1
        • PB____
          PB____ last edited by PB____

          I think all trailing zero's can be skipped (so not just the fourth one :) ). I've used {} several times and haven't had issues with it (other than that opacity defaults to 0).

          To me this seems like a bug, but I could work around it in the following way:

          spr = createSprite()
          spr.pos = {}
          
          loop
            clear()
            var pos = spr.pos
            printAt( 0, 0, pos.x )
            printAt( 0, 1, pos[0] )
            pos.x += 1
            pos[0] += 1
            spr.pos = pos
            update()
          repeat
          

          It's not ideal, but I hope it helps :)

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

            Oh yeah, I'd already worked around it - it was just a bit of a surprise to see the hard crash! :)

            1 Reply Last reply Reply Quote 0
            • Willpowered
              Willpowered Fuze Team last edited by Willpowered

              @pobtastic Thanks for the report. I can confirm that in the next patch the hard crash is fixed but also that for the time being spr.pos still cannot be manipulated in either of these ways (It's on our to-do list). PB's workaround is the intended way to do this currently- Pull out the variable from the sprite, manipulate it, and then put it back in the sprite.

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

                Use spr.x and spr.y maybe ? Or setSpriteLocation(spr, x, y)

                Or am I taking the example a bit too literally? :P

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

                  Oh yeah, the point is to be able to manipulate a vector other than the sprites own properties. I actually found this ages ago, I just randomly fired up a version of Jet Set Willy I have and found it again. The issue there being that, the characters "walk across the frame" and you only change sprite x once the tracking x reaches % 8 == 0.

                  Something like this;

                  // Work out the current frame based on the tracking "x".
                  game.guardians[id].frame = ( int( game.guardians[id].pos.x ) >> 1 ) & 3
                  
                  // Only update the sprite "x" on a byte boundary.
                  if game.guardians[id].pos.x % 8 == 0 then
                    game.guardians[id].x = game.guardians[id].pos.x
                  endIf
                  
                  // Change frames based on movement, and not time.
                  setSpriteAnimFrame( game.guardians[id], game.guardians[id].frame )
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post