Odd error in Treasure Grove


Board: Treasure Grove. Lang: Javascript
Bugs or bad coding? You be the judge.

I keep getting “Upper or lowercase problem. Try this.distanceTo().” for the 2nd line of following function.

function findTheBestItem(obj3) { // function to sort array for highest value and range
	if (this.distanceTo(obj3) < 30) {
        if ((obj3.bountyGold > itemValue) || (obj3.bountyGold === itemValue && targetDis > this.distanceTo(obj3))) { // best item of nearest items
            itemValue = obj3.bountyGold;
            itemPos = obj3.pos;
            this.say("Item Set");
            actionNow = "goForIt";
        } //end of qual sorter if
        else {
            this.say("I didn't see anything I like.");    
        } //end qual sorter else
	} // end of distance filter if
	else {
		this.say("Nothing in range, boss.");
	} // end of distance filter else
} // end findTheBestItem

Still working on the function. So don’t beat me up too badly. Got stuck on this error.

The object passed to it a variable created from an array:

var items = this.findItems(); //create array of items
var item = items[iii];

Off topic idea: I think it would be useful to have a forum for trading code. I bet I could learn a lot from the C-level code of some of the top dogs.

I think that’s all of it. Thanks for the help!



Update: I’ve been commenting out sections of code to test the rest of it. I have been getting the same error for anything in that function that starts with “this.”.

Do this.* commands not function in functions?


Perhaps you should try creating another reference to this before the function:

var self = this;
function findTheBestItem(obj3) {
    if (self.distanceTo(obj3) < 30) {

I don’t think the value of this should change in that scope, but the Aether sandbox occasionally behaves differently than normal JavaScript.


I will give that a shot. Thanks.