Understanding Compilation Errors

Understanding Compilation Errors

> LeekScript Tutorial

You code your AI like a blessed. The lines scroll, and the names of very logical variables and functions, such as sfatyu_2 follow one another, life is good... Suddenly ! The "save" key is pressed and your code is checked by the compiler. It supports your gaze, intensely... And here is the drama ! One (or more!) big red lines appear at the bottom of your editor, what can these strange and esoteric magic formulas mean?

This guide will reveal the truth to you so that you too can become knowers.

An end of statement was expected here

An end of instruction? Yes, it's the ";" at the end of each line. This message indicates a line where one of these characters is missing. Be careful though! the line indicated is in general the line preceding or following that incriminated.

!Missing one;

Here a ";" is missing at the end of line 18, and the message tells us that the line before useWeapon does not have its semicolon!

Fix: moveToward(enemy);

Unexpected end of file

More insidious! It's the same error as the previous one, but this time it's the last line of your AI that doesn't have a semicolon. !unexp EoF

Fix: useWeapon(enemy);

This can also be due to an unclosed String: !EoF 2

Fix: say("I won!");

Unknown variable or function

Who forgot to declare their variable? A short return to the tutorial on Variables and the tutorial on Functions may prove useful.

!var or func unknown

Here, the enemy variable is not declared. You must first create it with the var keyword. Fix: var enemy = getNearestEnemy();

And for this one then? !ex unknown func

Well the author is just a monkey with a keyboard, and didn't see that he used getNeerest (which doesn't exist) instead of getNearest, declared just above.

This variable name is unavailable

You cannot redeclare a variable with the same name of an already declared variable.

![](https://imgur.com/Qx5n006.png)

Correction (ugly): var moi2 = 1 A better fix would be to use names that really match the role of your variables.

Warning: This error can also appear because of the name of a global variable.

This error will also fall on you if you use a comma instead of the revered semicolon: ![](https://imgur.com/cCpqtxS.png)

Fix: var enemy = getNearestEnemy();

This is due to the inline variable declaration: var variable1 = 1, variable2 = 2; is perfectly valid syntax (see Variables).

This function name is unavailable

Like the previous error, you cannot reuse a function name that has already been used.

![](https://imgur.com/UUfrixR.png)

Correction (very ugly): function getNearest2() {

Cannot use this parameter name

So we're trying to use the name of a global variable as a parameter name, huh? Do you know what it could cost you if you fell out with one of my less friendly colleagues?

![](https://imgur.com/xnAOUAV.png)

Correction :

Closing parenthesis expected

As the error message indicates, the indicated line is missing a parenthesis. !wrong if

Here line 19 of the code should be if (not isAlive(enemy)) {

A value was expected here

A function call not closed?? Here's what you get! !expected value

Fix moveToward(enemy);

Incorrect number of parameters

Parameters? kezako? A quick review of the Functions tutorial is in order!

!nb incorrect param

Here, the moveToward function accepts from 1 to 2 parameters, and we give it 0. Obviously the compiler hits our fingers. Fix moveToward(enemy); or moveToward(enemy, mp); with mp a number.

Note that you will get the same error if you give too many parameters to a function (Eg: moveToward(enemy, mp, thing);).

Not all blocks have been closed

What's a block? Well it's a section of code surrounded by { }. Here, we opened a block with { without closing it. !blocks not closed

Here the } is missing after the end of the if. The compiler therefore indicates the end of the current block (here the end of the file) to indicate that we forgot to close all the blocks. Correction :

No blocks to close

This situation is the reverse of the previous one. We closed a block av