Language Features
A list of all syntax elements available in the language.
Syntax will be described in the following format:
Input
The input type written in percent %
signs.
Literal
The raw characters.
Required Space
An underscore _
character.
Repetition
Three period ...
characters.
New lines must be respected. Spaces are typically optional but occasionally required.
Variable Use
Get the variable value.
%name%
Examples
var = 10
if var == 10 /print {var}
Variable Assignment
Set the variable (L) to the result of the statement (R).
%name%=%statement%
Examples
name = "BaeFell"
age = 10
word = "hello"
var = word
sum = 5 + 5
first = second = "hello"
Structure
Creates a data object with given properties. MUST be followed by a block. The block must contain ONLY variable assignment root statements.
struct_%block%
%variable assignment%
...
%close block%
Examples
person = struct {
name = "BaeFell"
age = 42
}
if person[name] == "George" /print no
/print {person[name]} is {person[age]} years old
Sum
Return the sum of the statement (L) and the statement (R). If either statement is a non-numerical value the result will be null
.
The +
operator will attempt to concatenate strings.
%statement%+%statement%
%statement%-%statement%
%statement%*%statement%
%statement%/%statement%
Examples
fifteen = 10 + 5
result = fifteen + 10
if result == 25 /print yes
greeting = "hello " + "there"
five = 10 - 5
result = five - 2
fifty = 10 * 5
result = fifty * 10
ten = 50 / 5
result = ten / 2
Compare
Return the comparison result of the statement (L) and the statement (R). This is typically a boolean. Some comparators can return a numerical or atypical object result.
<=
Less than or equal to.
<
Less than.
>=
Greater than or equal to.
>
Greater than
&
And.
|
Or.
^
Exclusive or.
?
Alternatively (if null).
==
Equal to.
!=
Not equal to.
%statement%<=%statement%
%statement%<%statement%
%statement%>=%statement%
%statement%>%statement%
%statement%&%statement%
%statement%|%statement%
%statement%^%statement%
%statement%?%statement%
%statement%==%statement%
%statement%!=%statement%
Examples
assert 10 > 5
assert 10 >= 10
assert 5 < 10
assert 10 <= 10
assert true & true
assert true | false
assert false ^ true
assert null ? true
assert "hello" == "there"
assert "hello" != "there"
String Literal
A (semi-literal) text value. This supports interpolation using the {
and }
brackets.
"%text%"
Examples
word = "hello"
name = "baefell"
greeting = "{word}, {name}"
assert greeting == "hello, baefell"
Boolean Literal
A literal true/false value.
true
false
Examples
value = true
assert value
assert !false
Property Getter
Retrieve a property from an object. This returns a value. If the property was unable to be found on the object the value will be null
. The property name must be literal.
%statement%[%property%]
Examples
length = "hello"[length]
assert length == 5
assert length[type] == #integer
player = struct {
name = "BaeFell"
age = 42
}
assert player[name] == "BaeFell"
assert player[age] == 42
Property Setter
Accesses a property in an object. This behaviour is somewhat ill-defined, since it may not alter the property. Some types may use setters to call unary methods, e.g. string[char_at=1]
calling string.charAt(1)
.
%statement%[%property%=%statement%]
Examples
player = struct {
name = "BaeFell"
age = 42
}
assert player[name] == "BaeFell"
player[name="Phil"]
player[age=21]
assert player[name] == "Phil"
assert player[age] == 21
assert "hello"[char_at=0] == "h"
Selector
A selector in the Minecraft format, starting with the 'at' @
character. This supports interpolation using the {
and }
brackets.
This returns a list if multiple elements are selected or a single object if only one is found.
Please note domains are expected to override the selector to provide a relevant universe.
@%finder%[%property%=%value%,...]
Examples
players = @a[distance=..10]
for player = players {
/print {player}
}
for entity = @e[world={world}] {
/print {entity}
}
/print hello, {@s}
Script Literal
A script literal. The complete syntax must be an exact name of a loaded script. This defers to execution (to respect loading) but throws an error if no script is present.
%name%.script
Examples
script = other.script
run other.script
run script [name="BaeFell,age=42]
Run
Runs an executable, returning its result. Any key<->value data store can be provided as a starting variable map. The result of the executable is returned.
run_%statement%
run_%statement%_%statement%
Examples
run other.script
run other.script [name="BaeFell,age=42]
var = 10
run other.script [var=var]
vars = [hello="there"]
run function vars
Syntax
Defines syntax that will be available following this in the current script parser. Statement inputs are specified with %name%
where name
becomes a variable name available in the syntax statement.
The new syntax has a lower priority than built-in syntax constructs.
syntax_%string%=%statement%
Examples
syntax "greet %person%" = /print hello, {person[name]}!
greet [name="BaeFell"]
greet struct {
name = "BaeFell"
}
Import
Acquires a resource from an external script. This runs the script and stores its result in the named variable.
This does NOT provide the script object, since this is already obtainable using the Script Literal syntax.
This is primarily designed for interfacing with native libraries (e.g. math
).
import_[%name%,...]
Examples
import [math]
result = run math[floor] 5.5
assert result == 5
result = run math[ceil] 5.5
assert result == 6
/print {run math[max] [5, 6]} is 6
Require
Asserts that the given variable keys are known. Their values may be null
, as long as they have been assigned in the context. This will attempt to pack anonymous arguments into the variable keys if none are present.
This is designed for input checking of functions and sub-scripts.
require_[%name%,...]
Examples
require [name, age]
require []
require [name, result]
Null Literal
An empty (nothing) value.
null
Examples
word = null
assert word == null
Map Literal
A map of key <-> value pairs. This is analogous to a structure but lacks the utility.
There is NO empty map literal []
since this is indiscernible from an empty list.
[%name%=%statement%,...]
Examples
map = [word="hello", name="BaeFell"]
var = "hello"
map = [var=var]
assert map[var] == var
List Literal
A list of values.
[%statement%,...]
Examples
list = ["hello"]
list = ["hello", "there"]
assert list[size] == 2
for word = list {
/print {word}
}
list = ["hello", "there", 1, 2, null]
Kind Literal
A type reference. Please note that 'kinds' are approximate (rather than definite) types.
#%name%
Examples
type = #string
assert "hello"[type] == #string
Inversion
Converts the following statement to a boolean value and inverts this.
!%statement%
Examples
var = !10 == 10
assert !var
Interpolation
A helper copy of string interpolation for use in code. This is added only for parity and has no necessary use. This may assist with order of operations.
<div data-gb-custom-block data-tag="statement"></div>
Examples
var = 10
var = {var}
var = {10 + 10}
If Statement
Converts a check statement (L) to a boolean value. If this value equates to true, runs an action statement (R). If the value is not true the action statement will be skipped. A block start {
is permitted after this.
if_%statement%_%statement%
Examples
if 5 == 5 /print yes
var = 5
if var == 5 {
var = 10
}
While Statement
Converts a check statement (L) to a boolean value. If this value equates to true, runs an action statement (R).
This will be repeated until the result of the check statement equates to false.
A block start {
is permitted after this.
while_%statement%_%statement%
Examples
while 5 > 0 /print forever
var = 5
while var < 0 {
var = var - 1
}
assert var == 0
Function Statement
Creates an executable object that can be run under control. This is designed to be followed by a block section.
Root variables are unavailable in functions - they must be provided in the run
statement.
Internally, this simply returns raw child statement.
function_%statement%
Examples
run function {
/print hello
}
func = function /print {greeting}
run func [greeting="hello"]
func = function {
require [name, age]
/print {name} is {age} years old
}
parameters = struct {
name = "BaeFell"
age = 42
}
run func parameters
func = function {
assert {var} == null
}
var = 10
run func
Do Statement
Runs a statement (R) in the context of an object (L). The properties of the object are available as keywords local to the area. A block start {
is permitted after this.
do_%statement%_%statement%
Examples
do "hello" {
var = char_at 0
assert matches "hello"
}
do player {
send_message "hello, {name}"
}
For Statement
Consumes a list of values, assigning each one to a variable (L). For each value, runs an action statement (R). If the list of values is empty the action statement will not be run. A block start {
is permitted after this.
for_%variable_assignment%_%statement%
Examples
for word = ["hello", "there"] {
assert word[length] == 5
}
Command Statement
Executes a Minecraft command from the context of the script runner. This supports interpolation using the {
and }
brackets. The result of this is typically a boolean value, determining whether the command executed correctly.
The script runner will receive any text output or effects of the command.
/%text%
Examples
/teleport @s ~ ~1 ~
word = "world"
/say hello {word}!
/say {word[length]} letters
Block Open
Opens a block. This hijacks the parser to combine the following lines into a single executable statement.
Nothing may follow the opening character in the same line.
{
Examples
{
/print hello there
}
if 5 == 10 {
/print uh oh something is wrong
}
for word = ["hello", "there"] {
/print {word}
assert word[length] == 5
}
Block Close
Closes a block and returns to its previous parsing task.
This MUST be placed on its own line. This must follow a block opening.
}
Examples
{
/print hello there
}
if 5 == 10 {
/print uh oh something is wrong
}
for word = ["hello", "there"] {
/print {word}
assert word[length] == 5
}
Assertion
Evaluates the result of a statement as a boolean. If the value is true, returns true.
If the value is false, this throws an error and terminates the running of the script.
assert_%statement%
Examples
assert 10 == 10
assert "hello" == "hello"
var = 5
assert var == 5
assert "hello"[char_at=0] == "h"
Last updated