Understanding Compilation Errors

Understanding Compilation Errors

> LeekScript Tutorial

You're coding your AI, happy as a clam. The lines scroll by, and very logical variable and function names 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 stares back at you, intensely... And then, disaster strikes! One (or more!) big red lines appear at the bottom of your editor. What could these strange, esoteric magic formulas possibly mean?

This guide will reveal the truth, so that you too can join the ranks of those in the know.

Unknown variable or function

Who forgot to declare their variable? A quick look back at the Variables tutorial and the Functions tutorial may come in handy.

!var or func unknown

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

And what about this one? !ex unknown func

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

Unavailable variable name

You can't redeclare a variable with the same name as a variable that has already been declared.

![](/user-image/b5/2d/b52db71d200ccd28889d996f04f08795d78ae6bb1bc3f8672d3b64f301e3aed7.webp)

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

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

You'll also run into this error if you use a comma instead of the sacred semicolon: ![](/user-image/51/3a/513a2ab72e76dbbcd758ecdbb98bcfb599f4cf5269f0eaa7edf155be275e261a.webp)

Fix: var enemy = getNearestEnemy();

This is because of inline variable declarations: var variable1 = 1, variable2 = 2; is perfectly valid syntax (see Variables).

Invalid function name

As with the previous error, you can't reuse a function name that's already taken.

![](/user-image/df/9a/df9a501a8f76eca98f3d8db9584d5e12887c729ce90f215114b0d2f94863fc5c.webp)

Fix (very ugly): function getNearest2() {

Invalid parameter name

So, trying to use the name of a global variable as a parameter name, are we? Do you know what that could have cost you if you'd run into one of my less friendly colleagues?

![](/user-image/4b/32/4b3220098aab1b31872b53cdb4b8b1bafbf635066022b43a529539cd107ed878.webp)

Fix:

Closing parenthesis expected

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

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

A value was expected

A function call that was never closed?? This is what you get! !value expected

Fix: moveToward(enemy);

Invalid number of arguments

Parameters? What are those? Time to go back to the Functions tutorial!

!wrong param count

Here, the moveToward function takes 1 or 2 parameters, and we're giving it 0. Of course, the compiler slaps us on the wrist. Fix: moveToward(enemy); or moveToward(enemy, mp); with mp a number.

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

Some blocks remain open

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. So the compiler points to the end of the current block (here, the end of the file) to tell us we forgot to close all the blocks. Fix:

No block to close

This is the opposite of the previous situation. We closed a block with } without opening it first... !block to close

Fix: if (not isAlive(enemy)) {

Opening parenthesis expected

Take another trip to the Functions tutorial: even when you have no parameters to pass to a function, you must at least write the parentheses ().

![](/user-image/6c/cb/6ccbade5a10251a86c3291390cee6a3ed5e532dd7c8c3ec23e2b0649d0299d97.webp)

Fix: function getNearest() {

Parameter name expected

As before: when you declare a function, don't forget to close the parentheses before the {.

!Parameter name expected

Fix: getNearest() {

While is expected after do block

How about a quick trip to the Loops tutorial? A do-while needs a while at the end of the block.

![](/user-image/cd/bb/cdbbd97bb14005f258c0a857d22e37a887e27194c9e626e9c4653c7354bd80fb.webp)

Fix: } while(true);

What do you mean, nobody uses do while?

A variable name is expected...

A variable name was expected

![](/user-image/ba/6e/ba6ea13d7a3a7fb77c85495e61848329a25e822f8e9049c03ebdd75f3afb9a6e.webp)

A variable name is expected after the global keyword

![](/user-image/0e/83/0e83945f91922eb9a9d3e792e87afa4fababc8e99b5c4feea0b89d65359c0cad.webp)

In both cases, we forgot to give our variable a name. A quick trip to the Variables tutorial wouldn't hurt.

Fix: var myVariable = 1; global myVariable = "Variable";

This else has no matching if

An else condition (or else if) must always be preceded by an if condition (see Conditions). We're civilized people here! No else without an if, or else you'll get your knuckles rapped.

![](/user-image/56/9e/569e6713bc07c4002c0e43552f35687bb481c93f9ed0372a55db5c79effd4367.webp)

Fix:

Incomplete expression

You'll get this error when you don't follow the syntax of a particular expression. Here, it's a ternary. If you don't know ternaries, they're a one-line way of writing if {} else {} (see Conditions and Operations).

![](/user-image/cb/cb/cbcb50f396353ac7e8686f74ce9df3c62ba8bf4e3b680f60c48858f43a5459cf.webp)

Fix: (getAliveEnemiesCount() > 0) ? getNearestEnemy() : getEnemies()[0];

What do you mean, this code is useless? How dare you! Do I criticize your code?

Invalid character

A semicolon, we told you! Not quite a period, not quite a comma: a bit of both. The invalid character error will hit you like a ton of bricks.

![](/user-image/e1/23/e123a4ae2d1dbfc6dd0f383ad4c5f7ce7adefc1027223a2f0b3ab9b2f79fece8.webp)

Fix: var enemy = getNearestEnemy();

This operator is unexpected here

![](/user-image/5d/7e/5d7e3e9168722f6db02400785ba857ee0262ef3e5a087fcddece76e5fae5cdfd.webp)

Unexpected? You can say that again! How did you even end up there?? You must not use an operator (Operators) as a variable.

Functions can only be declared in the main scope

LeekScript only lets you declare functions in the main block: you can't declare a function inside another block.

![](/user-image/21/14/211442d31e4fdc7d115b4af63ed2a8f529d510d69a666798898bbc8cbeb84a83.webp)

![](/user-image/27/48/274891affcb46b971c2d90a28010685d6ef2f8e4ef2c536ce1a071fdeb54911a.webp)

Fix:

There is one special case where you can declare a function inside another one: check out the Functions tutorial.

Global variable can only be declared in the main scope

Same as above, but with global variables! A global variable can't be declared in any block other than the main block. Not in an if, not in a loop, not in a function. Period. Semicolon, even.

![](/user-image/62/6c/626c11cb6b49c7cd0e6df4b7e5efa5b8d00889ac4a3f7287d5e9ba7a05c51a1c.webp)

Fix:

An AI can only be included in the main scope

Using include is good; using it properly is better! Here, we're trying to include an AI somewhere other than the main block, and the compiler is watching us with scary eyes...

![](/user-image/2c/a4/2ca47ac049c515abaa983f719abb332bdb4b9a359a3d6632646931061aea415d.webp)

Fix:

Note: The author disclaims all responsibility if you fail to win using Pilow's AI.

Keyword break can only be used inside a loop

This error describes itself very well: break can only be used inside a loop (see Loops)

![](/user-image/97/b2/97b2e1f4bb486fe91014ed58dbcb6f63a8237818b1063c0ac736e81d5af79769.webp)

Fix:

Note: This code gives exactly the same result as an if, since the loop is broken on the first iteration. Still, it's pretty ridiculous, isn't it?

Keyword continue can only be used in a loop

Exactly the same error as the one just above, but with continue instead of break.

Note: Use the following code to make Pilow cry and heat up the server room:

It's not possible to add an instruction if there is already a break, return or continue in the current block

In the very specific contest for very long, self-explanatory compilation errors, here's the champion. If you get this error, it means you have an instruction placed somewhere in your code where it will never be executed. Indeed, in the example below, we put the debug after the break instruction, which takes us straight out of the loop!

![](/user-image/a7/dd/a7dd253ddfbe6771d56da9126b298e803863d087e9102988634883a31f467132.webp)

Fix:

As its description says, this error can also happen with a return or a continue.

![](/user-image/14/f0/14f0ec32dd6338e36621329dfdf4db173319c7bc8ef63763bf46c14e177fbce1.webp)