The following code works fine and the coin value is counted as normal:
var c = 0;
while (true) {
var coin = hero.findNearestItem();
if ( hero.findNearestItem()) {
hero.moveXY( hero.findNearestItem().pos.x, hero.findNearestItem().pos.y);
c += coin.value ;
}
if ( hero.time >= 30) {
break;
}
}
However, changing the variable “coin” to hero.findNearestItem() (I’ve bolded the changes below) gives the wrong value OR throws up null errors.
var c = 0;
while (true) {
if ( hero.findNearestItem()) {
hero.moveXY( hero.findNearestItem().pos.x, hero.findNearestItem().pos.y);
c += hero.findNearestItem().value ;
}
if ( hero.time >= 30) {
break;
}
}
Is it a bug or is there some mistake I’m making? Please let me know.