Navigation

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

    removeSprite() not working

    Beginners
    4
    15
    446
    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.
    • pianofire
      pianofire Fuze Team last edited by

      Please can you share or screenshot your code?

      I think that setTimer is expecting a user defined function but removeSprite should work by itself

      spikey 1 Reply Last reply Reply Quote 0
      • spikey
        spikey F @pianofire last edited by

        @pianofire omg, didnt know we have time event based callbacks, until you mentioned that setTimer() takes a function as a param. Cool.

        1 Reply Last reply Reply Quote 0
        • M
          Maxwello F last edited by Maxwello

          I was never able to get it to work.
          Following.

          If you remove it as you have and then right after try and do something with it do you get the error "you can't do that to a removed sprite"?

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

            @Maxwello It is perhaps misnamed. It should probably be freeSprite or unloadSprite because it is actually freeing the memory used by the sprite. You can then use it again by reallocating using createSprite.

            M 1 Reply Last reply Reply Quote 0
            • M
              Maxwello F @pianofire last edited by Maxwello

              @pianofire hi yeh sorry. I meant it doesn't remove it but it does remove it enough to think it's removed it and not let you use it. Atleast last time I tried nearer end January so I was wondering if the same still applies hoping that might help with finding the error if there is one

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

                @Maxwello Do you mean it doesn't remove it from the screen? It certainly should do. Do you have an example?

                M 1 Reply Last reply Reply Quote 0
                • N
                  Nichson last edited by

                  Hi, so excited for all the answers!

                  Here's a picture of the code and the error message. I can't seem to put any function inside the parameter of settimer(), also tried with setspriteanimation().

                  My problem is I'm having a sprite show up for a couple of seconds which I later want to remove automatically.

                  Pictures of the problem:
                  https://ibb.co/72NPg6t
                  https://ibb.co/xm3nPMj

                  P.S.
                  Really enjoying the program, it's amazing what you've done and it's really helping me to motivate myself to keep on learning programming.

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

                    @Nichson OK so settimer is expecting a user defined function not a built-in one so you would need to do something like this:

                    function removeSpriteCallback( sprite )
                      removeSprite( sprite )
                    return void
                    

                    and then call it like this:

                    setTimer (4, 1, removeSpriteCallback( explosion ) )
                    

                    I haven't tested this

                    N 1 Reply Last reply Reply Quote 0
                    • N
                      Nichson @pianofire last edited by

                      @pianofire So I tried this and the error message now is "incorrect number of parameters for function." for removeSpriteCallback(), which I wrote exactly as you did, strangely enough.

                      If I remove explosion from setTimer (4, 1, removeSpriteCallback () ) then it says: "Cannot perform this operation on a removed sprite."

                      FUNCTION: removeSprite

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

                        @Nichson OK I don't understand that.

                        I am also not really sure what you are trying to do here. Is there reason that you are starting a timer to remove the sprite rather than just removing the sprite?

                        1 Reply Last reply Reply Quote 0
                        • N
                          Nichson last edited by

                          Hmm, yeah well It's an exploision and I want it to loop just once. If I just leave it, it loops over and over again. :9

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

                            @Nichson it is difficult without seeing the rest of your code but I suspect that you are actually calling this multiple times (you can only remove a sprite once). Maybe consider making it invisible instead using https://fuzearena.com/help/view/setSpriteVisibility ?

                            1 Reply Last reply Reply Quote 0
                            • N
                              Nichson last edited by

                              Fixed it! :)

                              So I had a phase variable that was following the m (map). This made it impossible to change the phase variable as I was still at the same m.

                              Changed this and now the explosion works out well.

                              Great that you could help with the callback function, I had a test in school about callback functions, back then I couldn't grasp it but now It's making more sense.

                              Stay safe.

                              Regards,

                              1 Reply Last reply Reply Quote 3
                              • M
                                Maxwello F @pianofire last edited by

                                @pianofire
                                Yes that's what I meant sorry.
                                The code would execute meaning the game would run but the sprite would not be removed (it was the player sprite as it happens) I had another action like print "aaa" and another (which escapes me) either side of the removesprite which would happen so I know it was getting to that code.

                                But if I decided OK it doesn't remove it so let's after the removesprite say do something else with the sprite then when hitting run it would error saying can't do that with a removed sprite.

                                So I resorted to moving it off screen instead.

                                I can and will recreate it tomorrow

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