A quick guide to the language. New scripts start with the example at its end.
Quick guide; Here's a tutorial, and a quick script to showcase it.
; New scripts start with this code, so don't worry about copying it by hand!
; Everything after a semicolon ';' is a comment.
; It doesn't get saved with the script.
; A line that ends with a backslash '\' continues
; to the next line. This works even for comments,
; which is probably not what you want/expect!
; A line starting with a colon ':' is a compiler declaration.
; Most declarations are variable declarations, taking
; the form :[local/global] [int/double/string] [name]
; Variable names are a combination of letters, digits,
; dots '.' and underscores '_'. Names must start with a
; letter or underscore.
; Names containing special characters, or that reference
; string variables, must use the variable functions.
; These take the form
; [local/global].[int/double/string].[get/set]
; That's a handful, though, so you can use the first
; character in each word for short.
; You can also declare constants by using "const" instead
; of "global", but in this case you have to assign a
; value immediately, since it can't be re-assigned.
; Another type of declaration is :import [file], which
; imports the contents of the named file. Imported files
; can only consist of declarations, macro definitions, and
; comments, they can't produce any "output" (impulses,
; actions, etc). Macro usage is OK only if it doesn't
; produce "output", for instance inside of comments.
; This allows you to import common library macros
; without having to copy them. The compiler will
; ensure that an import only happens once for a given file.
; You can also do :name [script_name] to override the
; name of the script.
; A line starting with a variable name, followed by a
; colon, is defining a label. Labels are special variables.
; They are automatically replaced by a line number, and
; exist to make 'goto' and 'gotoif' easier to use.
; A line starting with a hashtag '#' is defining a macro.
; Simple macros are "#macro_name macro_body".
; Macro-functions can be be defined with
; #macro_name(arg1, arg2, ...) macro_body
; Macros can reference other macros, and also be nested
; inside macro calls. Macros are referenced using curly
; brackets '{}' and act as text replacement.
; An example: "#concat(a, b) {a}{b}" defines a macro
; function that combines its arguments.
; {co{concat(nc,at)}("hi, there")} would result in
; "hi there" by applying the function twice.
; There are a few builtin macro-functions: {len()} returns
; the length of its argument (including any whitespace),
; and {lua()} evaluates its argument as a Lua chunk
; (don't forget to return a value!).
; The "macros" {[} and {]} return a single "{" and
; "}" respectively, and are used for escaping curly-braces.
; {} (the empty macro) will result in "{}", which is sometimes
; useful.
; Macros are useful when dealing with large amounts of
; copy-pasted code, and macro-functions are good for
; more complicated code-generation needs.
; Operators, and their precedence (internal names in quotes):
; ^ // exponent "pow", logarithm "log" (*not* floor-division!)
; * / % multiply, divide, modulo "mod"
; + - add, subtract
; %& bitwise-and "and"
; %^ bitwise-xor "xor"
; %| bitwise-or "or"
; . string concatenation. Automatically
converts int/double to string. Usually
requires space to parse correctly.
; == != < <= > >= comparators
; && & and
; || | or
; = assignment. Can be prefixed with other
; operators, e.g. '+=', '*='. Must come
; 2nd on a line, after a variable name!
; Tips: Don't forget to consult the drop-down dialog for
; the full list of all available functions.
; Have fun!
; A fun game: Try guessing what all these lines will compile to,
; then re-import the compiled result and see if you were right.
; This is needed for full-speed execution
:budget_cap max
:local int i
:local double test
:local string var
; Lines that return impulse become... well, impulses
wakeup()
; Lines that return bool become conditions
isTowerTesting()
; This is a macro, one that uses Lua to collapse
; expressions into a single constant
#collapse(expr) {lua(return {expr})}
; Everything else is an action
; All variables are initialized to zero/empty string automatically
label:
dig(i % 4, i / 4)
i += 1
gotoif(label, i < {collapse(4 * 4)})
; You can do math on labels, too!
i = label * 5
; This is how you can use macros to cut down on duplication
#common_expr (i - 2) * (i - 1) / 2
; This is a valid way to use variables, too
global.int.set("a*b", {common_expr})
var = "a*b"
gis(var, {common_expr})
; Continuing a long line. Note the space before the backslash,
; that doesn't get included automatically.
var = "This is a really long string that probably shouldn't keep \
going on like this and yet it does."
; This is how you use variables as operators
var = '+' ; Single quotes works too
test = a.d(3., var, 0.)
var = "=="
gotoif(99, c.i(3, var, 3))