Migrating from LeekScript 1 to 2

Migrating from LeekScript 1 to 2

> LeekScript Tutorial

This guide covers the various points to check if you want to migrate your AI from LeekScript 1 to 2. See the LeekScript 2 page for more information on the version itself.

Enabling LeekScript 2

To enable LeekScript 2 on an old AI, just click "LeekScript 1" on the left of the status bar at the very bottom of the editor. A menu will open, and you can click "LeekScript 2" to enable it. The AI will be analyzed with the new rules right away.

Pass-by-reference by default

In LeekScript 2, unlike LeekScript 1, all values are passed by reference, except primitive values (numbers, booleans, strings).

So you can remove all the @ from your code. (Note: at the time of writing, compiling with the @ does not work.)

If you've written recursive algorithms with arrays, for example, make sure to manually copy the arrays passed as parameters with the clone() function on each call.

References

In LeekScript 2, you can't make references to a number, a boolean or a string. You'll have to wrap these values in an array or an object to reproduce this behavior.

Using classes and objects

Reserved keywords

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: you'll have to rename some of yours if needed.

Operation costs

Because of the new rules, especially pass-by-reference, LeekScript 2 can consume far fewer operations. If you used conditions on the current number of operations, such as if (getOperations() < 15000000) for example, your AI may behave differently.

arrayFilter

The arrayFilter function got a fix: the resulting array is reindexed, so it is no longer associative with some null values. Make sure to update your algorithms if this applies to you.

The ^= operator

The ^= operator changes meaning: in LeekScript 1 it was the power + assignment operator, and in LeekScript 2 it is now the bitwise XOR (exclusive OR) + assignment operator.