eerr
eerr

Reputation: 1

Sprite_index is not set

I'm following a YouTube tutorial on a fighting game. Facing an error: Var <unknown_object>.sprite_index not set. The error was here:

if (sprite_index != sprKill_foward)
{
    sprite_index = sprKill_foward;
    image_index = 0;
}

codes for the object:

switch (state)
{
    case 0:  //< idle
        UpdateMoveIdle();
        break;
    case 1: //< move fwd
        UpdateMoveFwd();
        break;
    case 2: //< move back
        UpdateMoveBack();
        break;
    default:
        show_debug_message("Error! Unknown state: " + string(state) + " Maybe you added a state but haven't updated the Update method.");
        break;
}

if (nextState != state)
{
    //change the state
    state = nextState;
            
    //execute the start function for the new state
    switch (state)
{
        case 0:  //< idle
            StartIdle();
            break;
        case 1: //< move fwd
            StartMoveFwd();
            break;
        case 2: //< move back
            StartMoveBack();
            break;
        default:
            show_debug_message("Error! Unknown state: " + string(state) + " Maybe you added a state but haven't updated the Start method.");
            break;
    }
}

I tried checking every syntax error and reviewing the tutorial but I can't identify the error.

Upvotes: 0

Views: 90

Answers (1)

YellowAfterlife
YellowAfterlife

Reputation: 3217

If you are following an older tutorial in a recent GameMaker version, you will need to wrap the contents of the scripts inside a function - so if the script in the tutorial is

/// UpdateMoveIdle()
if (sprite_index != sprKill_foward)
{
    sprite_index = sprKill_foward;
    image_index = 0;
}

that would now be

function UpdateMoveIdle() {
    if (sprite_index != sprKill_foward)
    {
        sprite_index = sprKill_foward;
        image_index = 0;
    }
}

when you create a new script, there should be a comment inside with a link to a help page explaining the changes.

Upvotes: 1

Related Questions