Level: Brawlwood

Hello, I’m new to the world of code combat and I’m still learning new stuff and i saw encountered what seems to be a bug.
In the level Brawlwood, whenever I access the properties of coin, the editor throws an error “Cannot read property ‘pos’ of undefined”. However, it plays out the code perfectly and as required. But even during the fight it shows the big X sprite under the soldier.

The screen looks like this-

Also, when i view the contents of the variable items, it shows everything perfectly and not as undefined.

My question is- Why is it throwing such an error? Or am I doing something wrong?

Hey,

The issue is that you are trying to fetch items when they are not within the range(which is 80m) and in the line of sight. You need to run a conditional loop to check if the coins are visible. If they are, move to the position of the coin. Else, do something else(like move to that side of the map for instance).

Basically, it would become,

    var items = this.getItems();
if(items){ //check if any items are seen
//move to the item of choice
}
else //no items seen
{
//do something else to get closer.
}

Aditya

1 Like

Okay yeah… got it… I was under the impression that they would already be within that range, since the coins are around 70 to 76… But yeah, i should’ve probably kept a chack on it anyway… Anyway, thanks a lot :slight_smile: :smiley:

Aditya, thanks a lot for clearing that up!

I had the same problem but didn’t bother to open a thread.

I feel it’s not perfectly intuitive because there’s no such thing as fog-of-war or a visual marker for ranges (@nick) when units are selected and underscored by that big red cross.