diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 61b23cc158..fa9fe13c9b 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -8101,11 +8101,27 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx) delete this; return nullptr; } - else if (Index->isConstant() && static_cast(Index)->GetValue().GetInt() <= 0) + else if (Index->isConstant()) { - ScriptPosition.Message(MSG_ERROR, "State index must be positive"); - delete this; - return nullptr; + int index = static_cast(Index)->GetValue().GetInt(); + if (index < 0 || (index == 0 && !ctx.FromDecorate)) + { + ScriptPosition.Message(MSG_ERROR, "State index must be positive"); + delete this; + return nullptr; + } + else if (index == 0) + { + auto x = new FxConstant((FState*)nullptr, ScriptPosition); + delete this; + return x->Resolve(ctx); + } + else + { + auto x = new FxStateByIndex(index, ScriptPosition); + delete this; + return x->Resolve(ctx); + } } else if (Index->ValueType->GetRegType() != REGT_INT) { // Float. diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index b344a12283..4308950600 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -181,15 +181,11 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c { if (sc.String[0] == 0 || sc.Compare("None")) { - x = new FxConstant((FState*)NULL, sc); + x = new FxConstant((FState*)nullptr, sc); } else if (sc.Compare("*")) { - if (constant) - { - x = new FxConstant((FState*)(intptr_t)-1, sc); - } - else sc.ScriptError("Invalid state name '*'"); + sc.ScriptError("Invalid state name '*'"); } else {