• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Destroy an instance once its animation is done.

garcj299

Member
So I have an enemy with its idle animation and death animation in the same sprite, and once it is killed it's supposed to do the death animation and then destroy that instance. Here's the code:
//animation and death animation


if (death_animation = true)
{
if (image_index = 33)
{
instance_destroy();
}
}
else //idle animation
{
if (image_index >= 8)
{
image_index = 1;
}
}

but for some reason once death_animation is true, it just continues doing the whole animation and not destroying even once the image_index = 33. I tried using the end animation event but couldn't get it to work. Any ideas?
 

garcj299

Member
oh my gosh it worked like a charm. Thank you so much. Can you explain why it worked? and why the other one didn't?
 

Slyddar

Member
Because image_index is a decimal, and depending on the image_speed it may never equal an integer. Note there is also an animation end event in other which you could use too.
 

Biscotto

Member
oh my gosh it worked like a charm. Thank you so much. Can you explain why it worked? and why the other one didn't?
The if ICODE] if (death_animation = true) [/ICODE] and if (image_index = 33) are wrong.
If you use only one = you are setting the variable to the indicated value. If you want to make an equality check you have to use ==.
 

Nidoking

Member
The if ICODE] if (death_animation = true) [/ICODE] and if (image_index = 33) are wrong.
If you use only one = you are setting the variable to the indicated value. If you want to make an equality check you have to use ==.
I see this thrown around so often, and it's not true. GML errs on the side of forgiveness and interprets assignments in this context as comparisons. I don't recommend that anyone get too used to using = when they should use ==, but if you keep telling people it's required, you're just getting in the way of the people solving the problem.
 
Top