Navigation

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

    Does anyone know what I'm doing wrong here?

    Beginners
    3
    5
    497
    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.
    • poof92
      poof92 last edited by

      I have a sprite that's spawned every so often and it works but it has to shoot as well so I implemented the same shooting method as my other sprites but it gives me an error message I'm sure I'm doing something wrong.
      20221025_163728.jpg 20221025_163732.jpg 20221025_163736.jpg 20221025_163740.jpg

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

        Show the code where you populate the EnemyShip sprites. It seems that their is one sprite less than the code expects. What is maxEBS3? Is it a constant or can it change?

        My guess is that you have maxEBS3 - 1 sprites to start with, and when you remove sprites from your array, the array shrinks, but you still go from 0 to maxEBS3 in your loop.

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

          MaxEbs3 is my bullet sprites for my 4th enemy ship that shoots

          20221026_090043.jpg 20221026_090047.jpg 20221026_090050.jpg 20221026_090054.jpg

          Dave 1 Reply Last reply Reply Quote 0
          • Dave
            Dave Fuze Team @poof92 last edited by Dave

            @poof92 If your removeGameSprite() function is changing the size of the array (by copying it into a new array with the old element removed), then now your maxEbs3 variable will not correspond to the size of the array anymore.

            You could try always using len() instead, so that it is checking the size of the array and never counts past it - but.. I think you will run into a problem.

            I have tried a similar approach as this before to sprite handling, where you remove sprites from the arrays and remove the elements so that you never "waste" an iteration in your for loops - but this will end up skipping over sprites when you remove them.

            You will need to change these for loops into while loops, using a manual counter variable which only increments when you do not remove a sprite. They would only loop while this counter is less than the len() of the array. When you remove one, and the array changes size, the index variable will now point to the next sprite along in the array, since they've all been shunted down.

            Hope this makes sense.

            1 Reply Last reply Reply Quote 3
            • poof92
              poof92 last edited by

              Ok thanks a ton I'll give it a try

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