Multiplayer Treasure Grove - findItems() not working?


#1

OK so I have been working on this for a bit. Obviously a lot more to this, but initially I thought I had unset the “coin” at some point so I spent time debugging that. Finally I just tried the following to test if I was going crazy:

loop {
var coin = this.findNearest(this.findItems());
if (coin === null) {
this.say(“THIS FUNCTION IS BROKEN BOOOOOO!”);
break;
}
}

It never finds an item. There could be a coin right next to the dudes head, and he still won’t find it. The enemies array seems to work no problem, is the items array not allowed on this level or something?

Hoping someone else has run into this issue and found a solution.


#2

Hello, reign, and welcome. Please format your code according to the FAQ.

Here’s your problem: At the very beginning of a level, there is nothing but your hero and the map. This is the time when your code starts running. If the map does not start with coins on the field, coin will be null. This is why it is always good policy to check for everything, e.g

loop {
    var coin = this.findNearest(this.findItems())
    if (item) {
        // do stuff here.
    }
}

#3

‘if (coin)’ instead of ‘if (item)’