Syntax Overview - coldrockgames/doc-scriptor GitHub Wiki

The syntax of scriptor combines elements of gml, BASIC and command shell scripting.

Many design decisions were made with performance in mind, ensuring the parser remains lightweight and efficient, especially for scenarios requiring frequent runtime recompilation.

This led to these general syntax concepts.

General Syntax Concepts

1. You write a script, not a program

  • A scriptor script executes line by line, from top to bottom, like a command shell script.
  • The syntax does not support functions, classes, or constructors.
  • Flow control is provided through:
    • Loops (for, while, do...until
    • Conditional if statements
    • gotocommands
  • Use the exit command to terminate the script at any given point.

2. Every command must be on a single line

  • Multi-line statements, builder patterns, and { code blocks } are not allowed
  • Each line must be self-contained and executable.

3. "if" requires "then"

The then keyword, known from the BASIC language, has been included in the requirements of if-statements, to separate the condition block from the action block.

// This is an error
if self.hitpoints == 0 exit

// This is valid
if self.hitpoints == 0 then exit

4. There is no "else"

Due to the single-line rule above, if-then-else is implemented in the same way, you would do it in a command shell script: with goto and a jump over, like shown below.

The same pattern can be used to simulate a multi-line then part, by simply creating a jump label to the end of the block.

if some_var != 0 then goto nonzero
// do the part, when some_var == 0
goto go_ahead

nonzero:
// do the part, when some_var != 0

go_ahead:
// continue your script

5. No semicolon ; required

Since each statement is written on a single line, there is no need for semicolons to terminate commands.