Having trouble with “Hoarding Gold”. I’m getting an error on line 5 that says, "cannot read property ‘pos’ of null. What am I doing wrong? It doesn’t seem to me to be any different than any other time when my character has to read an X,Y position and move to it. Usually I use something like:
var coin = findNearest(findItem());
coinPosition = coin.pos;
coinX = coin.x;
coinY = coin.y;
this.moveXY(coinX, coinY)
I tried using the above first but couldn’t make it work, so I tried toying with it to get what I’ve got now, and it still doesn’t work.
var totalGold = 0;
loop {
var coin = this.findNearest(this.findItems());
if (totalGold < 25) {
this.moveXY(coin.pos.x, coin.pos.y);
totalGold = 0 + coin.value;
} else if (totalGold >= 25) {
break;}
}
this.moveXY(58, 33);
this.say("Done collecting gold!");
this.say(totalGold);