Sprite_index 未设置

问题描述 投票:0回答:1

我正在关注有关格斗游戏的 YouTube 教程。遇到错误:

Var <unknown_object>.sprite_index not set.
错误就在这里:

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

对象代码:

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;
    }
}

我尝试检查每个语法错误并查看教程,但我无法识别错误。

sprite game-engine game-maker gml
1个回答
0
投票

如果您正在遵循最新 GameMaker 版本中的旧教程,则需要将脚本的内容包装在

function
中 - 因此,如果教程中的脚本是

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

现在就是这样

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

当您创建新脚本时,内部应该有一条注释,其中包含指向解释更改的帮助页面的链接。

© www.soinside.com 2019 - 2024. All rights reserved.