LeekScript 2

LeekScript 2

> LeekScript

LeekScript 2 (formerly LeekScript 1.1) is the second version of LeekScript, the language of Leek Wars, released on February 28, 2021. It aims to clean up the language, make corrections and add oriented programming object.

Presentation

Since deep modifications are made to the way the language works, this is a version without backward compatibility which is activated manually by the user in the editor.

Version 2 is a step towards the future version announced in 2016. Many planned features are therefore present in version 2, allowing the language to be advanced gradually, these features being very beneficial for coding complex AI.

A dedicated migration help page is available here: LeekScript 1 to 2 Migration.

New features

Object Oriented Programming

Added object-oriented programming: classes and objects. See the Classes and Objects page for all the documentation on this addition.

The keywords new, class, extends, static, public, protected, private, implements, interface, constructor, this, super and instanceof are reserved for OOP and are therefore no longer available for variable or function names.

Pass by reference

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

The @ syntax is no longer used and is therefore deprecated everywhere. It is not possible in LeekScript 2 to create references to a primitive value.

References in tables

Ability to add references in arrays (and objects), allowing to create complex and/or recursive structures at a reasonable cost.

Examples of data structures difficult to achieve in 1 and very easy in 2:

clone() function

Added a clone(value, [level]) function to clone a value precisely:

Multiple errors

Several semantic errors returned in the editor 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 displayed below each error, instead of just one line before (also available in LS 1).

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

Semicolons not required

But it is always possible to use it of course. (also available in LS 1)

RAM size limit removed

The array size limit is removed, the cost in operations being sufficient to limit their use.

Fixes

arrayFilter

Fixed arrayFilter: array is correctly reindexed without leaving null values.

String "\\\\"

Fixed escaping the string "\\" which correctly displays a single \ instead of two.

Declaration of globals

Fix on global declarations across multiple files.

Operator ^=

Fixed ^= operator becoming the binary OR instead of the power.

Shuffle function

The shuffle function takes into account the random number generator connected to the combat seed and is therefore deterministic for the same seed. It could cause variations between two fights generated from the same seed, which impacts the tests.