removeSprite() not working
-
@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
-
@Maxwello Do you mean it doesn't remove it from the screen? It certainly should do. Do you have an example?
-
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/xm3nPMjP.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. -
@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
-
@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
-
@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?
-
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
-
@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 ?
-
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,
-
@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