Sections

In-code block-structures.

Sections are an indented block-structure that can occur within code. These are usually provided by some header element.

The line preceding the section is always finished with the : colon character. This marks a necessary indent.

Almost all syntax-types can be a section-header.

Inline Sections

Many section structures can be used in an inline format. This occurs when a necessary section-header is placed with no finishing : colon and no indenting of the subsequent line.

As this is a rather dangerous format, structures are permitted to disallow this behaviour and throw a compile-time error when being used in this way.

function test:
    trigger:
        if {var} is true // section header
        print "yes" // inline section
        print "bye" // inline section
// section ends here, the tree is closed

Sections can have different inline behaviour. Some will apply to the remainder of their current block, like the if conditional.

Other inline section headers may apply only to their current line, such as the monitor and loop ... in ... effects.

set {var} to a new object
monitor {var} // the monitor applies only to this line
print "done" // this is not in the monitor section

Block Sections

Most sections will be used in the block format, indented by one unit.

function test:
    trigger:
        if {var} is true: // section header
            print "yes" // section
        else: // section header
            print "no" // section

Compiling

Sections are compiled based on a tree structure, allowing code to be injected before and after the section body.

Inline sections are closed before their parent section (such as the member's trigger.) This behaviour can have some unintended consequences in some scenarios, so it is advised to disable inline use for a section unless this is properly tested.

Due to the way Skript handles variables, all jump instructions are likely to be symmetrical but, to make this easier for the verifier, each jump injects another label at the location during assembly to make sure the stack frame is properly calculable. These may be collapsed during compilation if the frame is symmetrical. An example is shown below.

if {bar} is true:
    if {foo} is true
    return false
return true

Last updated