1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    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

    Aug 14, 2019
    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.
    // 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

    Dec 13, 2018
    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

    Jun 26, 2016
    Or even simpler:
    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