1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Windows [HELP] Sprite index isn't working

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Pietuuh, Aug 14, 2019.

  1. Pietuuh

    Pietuuh Member

    Joined:
    Aug 14, 2019
    Posts:
    1
    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.
     
  2. pipebkOT

    pipebkOT Member

    Joined:
    Dec 13, 2018
    Posts:
    212
    @Pietuuh
    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.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,684
    Or even simpler:
    Code:
    sprite_index = choose(sPlayerPunchLeft, sPlayerPunchRight);
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice