GMS 2.3+ Setting image_index to 7 makes it 7.00 and the wrong frame.


I have created an inventory that uses a sprite to show the number of that item in the inventory. Then as I increase the number of that item in the inventory I increase the image_index of the sprite. For some reason when I increase this number by 1 it counts like the following:
1 2 3 4 5 6 7.00 8 9 10 11 12 13 14.00 15 16 ...
When it reaches 7.00 it acts the same as if it was at 6, then when adding one more it changes to 8 and acts as expected. The same thing happens at 14.00 and at many other values throughout which seem to be random (the next one is 25 then 28 then 31), but it is always these values when I run it. I have made it so my code only changes the image_index at one spot and then I put it in a step event to set it and print out the values.
image_index = num;
show_debug_message(string(image_index) + " " + string(num));
This will print out "7.00 7" and I am not sure why since that is the only are that the image_index of this object is changed. image_speed is set to zero in the sprite. If I instead set image_index to num+0.1 then everything works correctly, but I am not sure why I would need to do this. I have spent the last couple of hours on this and am starting to think that it might be corrupt, but I am not sure so I wanted to see if anyone else had any ideas. Thanks!


šŸ§ *penguin noises*
GMC Elder
I had a similar bug yesterday, it seems related to 2.3.0 changes.

The easiest way to solve this is don't use image_index directly. Have your own "item_image" variable, and then use draw_sprite to draw the sprite with that subimage. (I'd recommend that in general, since image_index can be silently changed behind your back if you change sprites to one with a different amount of subimages, it affects collision masks, etc - you have more control if you use a normal variable without side-effects)


šŸ§ *penguin noises*
GMC Elder
Can you declare image_index as an int64? Slyddar said it's fixed, but I'm curious. lol
Wouldn't that approach break if you have a non-integer image_speed, though? (e.g. basically every legacy project)