Navigation

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

    Sprite error

    Beginners
    6
    11
    292
    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.
    • A
      ahallett2002 last edited by

      Hey,
      I am trying to put stuff on the screen and it is giving me "Invalid variable access."

      My code is

      for i = 0 to len( rocks ) loop

      If anyone knows what the error is, please tell me!

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

        We're going to need to see far more than that! there's nothing wrong with that line alone. Unless it IS alone and there's no more :D

        A 1 Reply Last reply Reply Quote 0
        • A
          ahallett2002 @Martin last edited by Martin

          @Martin

          for I = 0 to len( rocks ) loop
                n = random( 4 )
                rocks[i].spr = createSprite()
                setSpriteImage( rocks[i].spr, rockImgs[n] )
               rocks[i].pos = { screen.x + random( screen.x * 2 ), random( screen.y ) } 
               rocks[i].vel = { random( -screen.x / 5 ), random( 32 ) - 16 }
              setSpriteAnimation( rocks[i].spr, 0, 39, 10 )
              setSpriteLocation( rocks[i].spr, rocks[i].pos )
          Repeat
          
          1 Reply Last reply Reply Quote 0
          • SteveZX81
            SteveZX81 F last edited by SteveZX81

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • PB____
              PB____ last edited by PB____

              Some things that might be worth checking:

              • is rocksImgs indeed an array containing 3 images?
              • Is the variable screen indeed a struct with the properties x and y?
              • what does the rocks array contain before going into this loop? Do the structs in the rocks array already have the properties spr, pos and vel?
              1 Reply Last reply Reply Quote 0
              • Martin
                Martin Fuze Team last edited by

                From the code snippet that's published above there are loads of variables being used that don't exist. So without further info, I would indeed expect to see an invalid variable access error. But I guess you have other code that you're not showing us.

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

                  It is working for me but I had to assume the variable/struct definitions were something like this:

                  struct rock
                    var spr
                    int pos
                    int vel
                  endstruct
                  
                  rock rocks[10]
                  
                  1 Reply Last reply Reply Quote 0
                  • pianofire
                    pianofire Fuze Team last edited by

                    BTW you don't need to create your own position and velocity properties as sprites already have them!

                    https://fuzearena.com/forum/topic/521/sprite-properties

                    1 Reply Last reply Reply Quote 1
                    • R
                      Richard F last edited by Richard

                      Is rocks a struct, or is it meant to just be an array of sprites? If it's the latter changing rocks[i].spr to just rocks[i] would probably fix it.

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

                        But we're all just guessing....

                        1 Reply Last reply Reply Quote 0
                        • A
                          ahallett2002 last edited by

                          I found out why it was giving me an error. I misspelled a word in the code and I forgot a ","

                          1 Reply Last reply Reply Quote 2
                          • First post
                            Last post