• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

(image index == x) in step event

shui.bdr

Member
i need to do something in a certain frame of an object, the code i wrote is:

GML:
if (image_index == 25)
{
    image_speed = 0;
}
it's wrote in the step event and it's very simple, but when the animation reach that frame the animation speed doesen't sets to 0, it's like gamemaker
dosen't even recognises that the animation is at the 25 frame and it doesen't read the code inside

p.s. sorry for the bad english
 

TheouAegis

Member
The image_index probably isn't 25, it's probably 25.001 instead. You can check if floor(image_index)==25, or if frame 25 is the last frame, you can just use the Animation End event. In GMS1 or earlier, you could also just check if image_index >=25 && image_index-image_speed<25.
 

Roderick

Member
To further what @TheouAegis said, you should never use if (x == y) unless you are comparing ints or bools. With numbers that can be fraction (doubles, floats, etc) the odds of the numbers being close but not exactly the same are too high to risk. You should always use >, <, >= or <= to compare, or if you need an exact match (ie, you must use ==), use floor(), ceil() or round() on one or both to make sure you're working with ints.
 

shui.bdr

Member
The image_index probably isn't 25, it's probably 25.001 instead. You can check if floor(image_index)==25, or if frame 25 is the last frame, you can just use the Animation End event. In GMS1 or earlier, you could also just check if image_index >=25 && image_index-image_speed<25.
i tried with the floor(image index) and with the other one, the animation doesen't stop anyways. i tried with the animation end event too
 

joeygopher

Member
What was the image speed before it reached 25? Is it always exactly 1.0? If it goes higher than that, I can see scenarios where it's not going to meet the criteria you're checking.

I'd just switch it to check if the image index is greater than 24 and not put a top bound on it. Then it doesn't matter if it's 24.2, 25.33 or exactly 25 or whatever. If it's higher than 24 then it's time to go back to image 0.
 
Top