Interpreter can't find method inside "self" (this) [JS]


#1

Hello, In the level “multiplayer-treasure-grove” I got this interpreter error:


#2

Pass “self” in to the function as a parameter and it works - at least, it has worked for me before…

function foo (self) {
// stuff
}

foo (this);


#3

Your solution did not work.
But moving the declaration to the top before the loop vanished the problem.

var self = this;
loop{
...
}

Even though, now another problem appeared:

The “x” mark does not tells any useful hint, only says “find the distance to a target unit”


#4

You also need to declare the function outside of the loop…

“scope” isn’t really taught yet in the lessons in the game it seems - of course, none of the levels really require an understanding of it yet either.