LeekScript 2

LeekScript 2

LeekScript 2 (formerly LeekScript 1.1) is the second version of LeekScript, the language of Leek Wars, released on February 28, 2021. Its goals are to clean up the language, fix bugs and add object-oriented programming.

Overview

Since it makes deep changes to the way the language works, this version is not backward compatible: each user enables it manually in the editor.

Version 2 is a step toward the future version announced in 2016. Many of its planned features are therefore already in version 2, so the language can move forward gradually; these features are very useful for coding a complex AI.

A dedicated page to help you migrate is available here: Migrating from LeekScript 1 to 2.

New features

Object-oriented programming

Object-oriented programming has been added: classes and objects. See the Objects and Classes page for the full documentation of this addition.

The keywords new, class, extends, static, public, protected, private, implements, interface, constructor, this, super and instanceof are reserved for OOP, so they can no longer be used as variable or function names.

Pass by reference

Non-primitive values, that is arrays and objects, are passed by reference by default. Primitive values (number, boolean, string) are always copied.

The @ syntax no longer has any use and is therefore deprecated everywhere. In LeekScript 2, you cannot create references to a primitive value.

References in arrays

You can now put references in arrays (and objects), which lets you build complex and/or recursive structures at a reasonable cost.

Examples of data structures that are hard to build in version 1 and very easy in version 2:

clone() function

A clone(value, [level]) function has been added to clone a value precisely:

Multiple errors

The editor reports several semantic errors instead of just one (also available in LS 1).

![](/image/encyclopedia/multiple_errors_2.png)

![](/image/encyclopedia/multiple_errors_1.png)

Full call stack

The full call stack is shown below each error, instead of a single line as before (also available in LS 1).

![](/image/encyclopedia/stacktrace.png)

Semicolons are optional

But you can of course still use them. (also available in LS 1)

RAM size limit removed

The array size limit has been removed: the cost in operations is enough to keep their use in check.

Fixes

arrayFilter

arrayFilter has been fixed: the array is properly reindexed, without leaving null values behind.

String "\\\\"

The escaping of the string "\\" has been fixed: it now displays a single \ instead of two.

Declaring globals

Global declarations across several files have been fixed.

Operator ^=

The ^= operator has been fixed: it is now the bitwise XOR (exclusive OR) instead of the power operator.

shuffle function

The shuffle function now uses the random number generator tied to the fight seed, so it is deterministic for a given seed. It could cause differences between two fights generated from the same seed, which affected tests.