Strict mode

Strict mode

> LeekScript

Strict mode is a LeekScript option, which can be enabled in the editor, that changes the behaviour of the language. It is intended for experienced players and is not recommended for beginners.

History

Strict mode was released in update 2.38.

Enabling it

Click the "LeekScript X" button at the bottom of the editor and tick the Strict mode checkbox. As with the version of an AI, strict mode applies to the AI and all of its includes.

Features

Fixed variable type

Variables initialised with the var keyword and a value keep the type of that value. The advantage is that you don't have to write the variable's type explicitly.

For example, without strict mode, you can write:

But in strict mode, the same code returns an error: Cannot assign value « "hello" » of type « string » to variable « a » of type « integer ».

The var keyword in strict mode is therefore equivalent to var in Java or auto in C++.

To still be able to assign a type different from the first value, you can give the variable the any type:

This code works even in strict mode.

Accessing outside an array raises an error.

In strict mode, accessing outside an array raises an exception and therefore stops the AI instead of returning null.

This behaviour is handy because the return type of an access to an Array is then X instead of X | null. It also avoids silent behaviours where null values would be used in computations.

More type warnings are returned.

In strict mode, many new warnings are returned: