Language: Javascript
Board: Gold Rush (still)
Again, this is probably something obvious to those of you who know what you’re talking about, but I’m stumped.
Script goal:
- Put items in an array.
- Sort array by distance from closest to farthest.
- Find the highest valued item w/in the closest 10 based on bountyGold.
- Strip out coordinates.
- Go there.
What actually happens:
Avatar the coordinates it’s walking to continually change.
var items = this.getItems(); //create array of items
var itemValue = 0;
// Sort by distance
items.sort(function(obj1, obj2) {return obj1.distance - obj2.distance;}
// find best of closest 10
for(var i = 0; i < 10; ++i) {
var item = items[i];
if (item) {
if (item.bountyGold > itemValue) { //if it's better, use it
itemValue = item.bountyGold;
var itemPos = item.pos;
}
}
}
if (item) {
// Strip coordinates
itemX = itemPos.x;
itemY = itemPos.y;
this.say(itemValue);
}
// Go for it
if (item) {
this.say(itemPos);
this.moveXY(itemX, itemY);
}
Shouldn’t it go to the coordinates? If not, how do I tell it to quit interrupting itself?