Skip to content

Labels

Labels are used to jump to a specific point in the script. They are defined by the label keyword followed by the label name and a semicolon. Labels can be used with the goto keyword to jump to the label.

Label names follow the same rules as variable names:

  • Names are case-sensitive, e.g. foo and Foo are two different names.
  • Names can only contain letters, numbers and underscores. Diacritics are not allowed.
  • Names must start with a letter or an underscore.
  • Names cannot be the same as a keyword.
  • Labels cannot have the same name as a variable, constant, function, rule or rule group.

Syntax of labels

1
2
3
4
5
// Creating a label.
label labelName;

// Jumping to a label.
goto labelName;

Example of a label

Age3AI.xs
1
2
3
4
5
6
7
8
void main(void)
{
    aiEcho("Hello from above the label!");
    goto _SayGoodbye;
    aiEcho("Hello from a part of the code that won't be reached!");
    label _SayGoodbye;
    aiEcho("Hello from below the label! Goodbye!");
}
AI Debug Output
00:00:00 (0): P#1 (Player 1) Hello from above the label!
00:00:00 (0): P#1 (Player 1) Hello from below the label! Goodbye!

Duplicate labels

The game does not prevent you from creating multiple labels with the same name. It's not fully clear what happens when you do this, but it's best to avoid it.