I love the smell of UnrealEd crashing in the morning. – tarquin
Syntax in functions and ForEach loops
goto labelname ;
The label name must be an identifier matching a label name in the immediately surrounding function or ForEach block. The label can also be outside the current code block, but it is not allowed to jump out of or into a ForEach block. Other loop types and If, Else or Switch blocks are unproblematic in that respect.
Syntax in state code
The syntax in states (outside any ForEach loops) is similar to that in functions, but there is a small difference:
goto expression ;
Instead of a simple identifier to specify a label, an expression is expected that evaluates to a name value. The simplest case would be a name literal, but you can also access variables or call functions here.
As with any other expression, the compiler can only check the syntax. In particular, the expression's result is not validated at compile-time, so it is possible to specify invalid label names. Such an invalid name will generate a runtime warning and stop state code execution as if the Stop statement was used.
Using GotoState() instead
As mentioned above, the GoTo statement for jumping to state labels can only be used in state code outside any ForEach loop. If you want to jump to a different state label from within a function, you can use the GotoState() function as described below.
- Warning: Functions called from within a ForEach loop in state code, as part of a function parameter expression or in similar nested context (such as the condition of a loop or an If statement) must not change the actor's state or jump to a different state label as side effect. Doing so will crash the engine with a general protection fault!
Within state code, the result of a GoTo statement is the same as calling the GotoState() function and only passing the label expression as the second parameter:
Thus the corresponding GotoState() call would be:
GotoState(, expression, False, True);
The last two parameters can also be omitted if the current state was not pushed onto the state stack with the PushState() function.
|Declarations||Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects)|
|Types||bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting|
|Literals||Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings|
|Flow||GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue|
|Specifiers||Super • Global • Static • Default • Const|
|UnrealScript||Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native|