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.
1
function test:
2
trigger:
3
if {var} is true // section header
4
print "yes" // inline section
5
print "bye" // inline section
6
// section ends here, the tree is closed
Copied!
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.
1
set {var} to a new object
2
monitor {var} // the monitor applies only to this line
3
print "done" // this is not in the monitor section
Copied!

Block Sections

Most sections will be used in the block format, indented by one unit.
1
function test:
2
trigger:
3
if {var} is true: // section header
4
print "yes" // section
5
else: // section header
6
print "no" // section
Copied!

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.
Skript Source
Instruction Assembly
Bytecode Compilation
1
if {bar} is true:
2
if {foo} is true
3
return false
4
return true
Copied!
1
loadObject bar
2
jumpIfEQ L0
3
loadObject foo
4
jumpIfEQ L1 // duplicates jump
5
push0
6
returnSmall
7
L0
8
L1
9
push1
10
returnSmall
Copied!
1
aload 0
2
ifeq l0
3
aload 1
4
ifeq l0 // label collapsed
5
iconst_0
6
ireturn
7
l0 // labels collapsed
8
iconst_1
9
ireturn
Copied!
Last modified 2mo ago