An error when there is no error


#1

So i’ve literally just copied the code from the heroes is path clear and I receive the error Line 10: tmp8[tmp9] is not a function. My code looks like this
. . .
var item = this.findNearest(this.findItems());
if (item && this.isPathClear(this.pos, item.pos)) {
this.move(item.pos);
}
else { this.move({x: this.pos.x, y: this.pos.y +5});
}


#2

Which level did you paste your code into?


#3

Stranded in the dunes, trying to unlock that giant muscular character.


#4

Compare what it said to do in the previous level to the level that your on now. If what it says is different then edit your code.


#5

Okay, so I looked at the previous level which was saving time, but that didn’t help what so ever because they are asking entirely different things and it was not required to use this.isPathClear. Anyway so my character for some reason will not attack enemies whom confront him, he just keeps walking to the right.

loop {
var enemy = this.findNearestEnemy();
// if no enemy continue walking
if (enemy) {
this.attack(enemy);
} else {
this.moveXY(this.pos.x + 10, this.pos.y);
}

}


#6

and this code looks incredibly logical and set up in the proper order. But yet he still continues to just walk to the right.


#7

I’m sorry, maybe its your computer?


#8

Same thing here, I’ve copied a code word for word, compared it with other codes, yet it doesn’t work. I’m in Copperfield Meadows in Backwood Forest, and one of the sample codes is incorrect, it’s item= self.findNearestItem()


#9

It’s really been annoying me now, I been trying for several hours to make this game work, but the stupid code warning has been cropping up in nearly every level, even if I’ve proved it’s correct.

I wish this could be fixed.


#10

Can you please post your code in triple backticks ( ` ) so we can see what may be the problem?


#11

I’ve done that.
Thanks!


#12

I meant copy your code from the game and paste it here in the forums so we can see it to help.


#13

Sorry,

while True:
    flag = hero.findFlag()
    if flag:
        pass  # pass is a placeholder, it has no effect.
        # Pick up the flag.
        self.pickUpFlag(flag)
    else:
        # Automatically move to the nearest item you see.
         item = hero.findNearestItems()''' This one's the wrong one
        if item:
            position = item.pos
            x = position.x
            y = position.y
            hero.moveXY(x, y)

#14

And what glasses are you wearing?


#15

hardened steel glasses.


#16

The problem is you do not have the findNearestItem() API. Your glasses have the following:

findItems
findNearest
findEnemies
isPathClear
findByType
distanceTo

Since you upgraded your glasses too much, you’ll want to use hero.findNearest(hero.findItems()) to replace every hero.findNearestItem() you see. Then you won’t see the error anymore. Or, downgrade your glasses to a pair that has hero.findNearestItem().


#17

It works now!
I haven’t degraded my glasses, I used the one you suggested; item = hero.findNearest(hero.findItems())


#18

Hello!

I have a problem at the same level (Copper Meadows).
My code is:

while True:
    flag = hero.findFlag()
    if flag:
        pass # pass is a placeholder, it has no effect.
        # Pick up the flag.
        hero.pickUpFlag(flag)
    else:
        # Automatically move to the nearest item you see.
        item = hero.findNearestItem()
        if item:
            position = item.pos
            x = position.x
            y = position.y
            hero.moveXY(x, y)

Please, help me! My hero doesn’t move to the flags or starts to move toward the flags and items but stops. I have error message for the line 5: "Code never finished. Its either really slow or has an infinite loop."
I have wooden glasses and softened leather boots.indent preformatted text by 4 spaces


#19

try this code @mamintix

don't post solutions