Skip to content
Austin edited this page Aug 23, 2022 · 1 revision

Sections

Sections are defined to be something that will produce their own code template. So either events or function (and maybe processes/entity events in the future). You can write an event like this:

event "Join" {}

Where Join can be replaced by any player event. Function are defined like this:

func functionName(param1, param2, param3) {}

Functions can return values using the return keyword.

Functions are called like functionName(arg1, arg2, arg3); The arguments can be any expression.

Variable Manipulation

You define a variable like this:

var variableName: scope = value;

However, this does not need to be used all of the time. If you use a variable without using a variable statement (var), it will default to a local scope. And for variable declarations, both the scope and value are optional. Meaning this would be correct: var variable; (although kind of redundant, it would add easier readability to your code).

Also, you don't need the var keyword in order to set a variable. variableName = value; is perfectly fine too. Infact, setting a variable without a var keyword is an expression itself, meaning syntax like this is valid: a = b = c = 5;. This statement will set a, b, and c to 5.

Math

In order to perform math, you can use *, /, +, or -. Please note that these operators are meant to be performed on numbers and not on strings. These operators follow order of operations, meaning that 2 + 5 * 3 will result in 17.

Grouping expressions are also allowed, so (2 + 5) * 3 results to 21. The only unary operator is the -, which just multiplies the value to the right by -1.

DF Blocks

In order to use DF Blocks like Set Variable, Game Action, Entity Action, etc... you can use this syntax

"block_name":"ActionName"<"tag_key1":"tag_value1","tag_key2":"tag_value2">(arguments);

This is a doozy to write, so I'm thinking about changing it something easier and reproducable. Tags are inputting from left to right, meaning that the first tag will be in the 26th slot, and the second tag will be in the 27th slot.

Because of how often SendMessage is used, a special syntax can be used: print (expression);

If Blocks

If statements can be created two ways

  1. Normal if block. Using an if just like if(a == b) {} just performs the standard = if variable. The conditions that are available are ==, !=, >=, >, <=, and <.
  2. DF If block: like "if_player":"NameEquals"<"tag1":"value1">(arguments) {}. This is similar syntax to the DF block, however in an if form.

Special Things

Lists can be created with [value1, value2] and can be indexed by list[1]. Nested indexes (and properties in a bit) are possible, meaning you can do list[1][2][1]. This works with expressions, so you can index a list by doing list[variable].

Dictionaries are created like Javascript, however, you can only use Texts for keys as that is what DF forced you to do. Example creation: months = {"january": 1, "febuary": 2, "march": 3, "april": 4}. You can get properties of a dictionary with months.january, months."january", or months["january"]. Currently, it is not supported to use expressions for a property.

Both indexing and getting properties also work with setting them (for ex. list[1] = "a";. However, as of right now nested setting does not work list[1][1] = "a";.

Loops

The syntax for loops is shamelessly stolen from Spark (although with something new).

  1. loop(local i to 10) {} goes from 1-10
  2. loop(local i from 5 to 10) {} goes from 5-10
  3. loop(local i from 10 to 5 step -1) {} goes from 10-5
  4. loop(local num in numbers) is a for each loop.

Break and continue are valid keywords, which are mapped to StopRepeat and Skip respectively.

Clone this wiki locally