• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows [HELP] Sprite index isn't working

Pietuuh

Member
Hi i'm new to GameMaker and I don't understand why this code isn't working. I have sprites sPlayerPunchRight and sPlayerPunchLeft and an object oPlayer. In oPlayer there's a left pressed event that has this code in it.
Code:
// Punching
WhichPunch = random_range(1,2);

if (WhichPunch == 1) {
    sprite_index = sPlayerPunchRight;
}

if (WhichPunch == 2) {
    sprite_index = sPlayerPunchLeft;
}
When i click the left mouse button nothing happens.
 

pipebkOT

Member
@Pietuuh
random_range(1,2) will return a random number from 1 to 2, but the value may be a real number like 1,65265. Real numbers can also be used as input arguments.
since it gives you a decimal number, the "if" code is not executed.

you should use the choose function instead of the random range,

WhichPunch = choose(1,2);


and use randomize(); at the start of your game.
 
Top