• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML I have an issue with if(image_index = x)

hana0rain

Member
This is a collision event

GML:
if (image_index == 19 or image_index == 38)
{
    healthManager_Obj.playerHealth -= healthManager_Obj.maxHealth * 0.1;
    hera_Obj.image_blend = $FF0000FF & $ffffff;
    hera_Obj.image_alpha = ($FF0000FF >> 24) / $ff;
    hera_Obj.alarm[0] = 0.25 * room_speed;
}
this code works at image_index = 19 but not in 38, doesn't make a difference if I separate them or if I get rid of image_index = 19 one completely. Some weird reason same code same rules won't work at the other image_index.
 

FoxyOfJungle

Kazan Games
What do you do to change the image_index? If what you are doing is skipping 2 image_index per step, then it may be that the value exceeds the desired number (19 and 38). I haven't tested it, but you can try this:

GML:
if (image_index >= 19 or image_index >= 38)
{
    healthManager_Obj.playerHealth -= healthManager_Obj.maxHealth * 0.1;
    hera_Obj.image_blend = $FF0000FF & $ffffff;
    hera_Obj.image_alpha = ($FF0000FF >> 24) / $ff;
    hera_Obj.alarm[0] = 0.25 * room_speed;
}
 

hana0rain

Member
What do you do to change the image_index? If what you are doing is skipping 2 image_index per step, then it may be that the value exceeds the desired number (19 and 38). I haven't tested it, but you can try this:

GML:
if (image_index >= 19 or image_index >= 38)
{
    healthManager_Obj.playerHealth -= healthManager_Obj.maxHealth * 0.1;
    hera_Obj.image_blend = $FF0000FF & $ffffff;
    hera_Obj.image_alpha = ($FF0000FF >> 24) / $ff;
    hera_Obj.alarm[0] = 0.25 * room_speed;
}
sprite animation is playing on loop at 10 frame speed. I am not really doing anything to skip it. The code you gave works actually but of course it executes multiple times.

edit: image index = 40 works I guess I'll just type that if I can't make it 38. Thank you
 
Last edited:

Nidoking

Member
Have you tried just rounding it? There's a known issue with image_index (and frankly, most integers in Game Maker) where even though you store an integer, it comes out as a tiny fraction off from that number. This includes the automatic increment of image_index.
 
Top