Help on The Dunes


#1

Hey guys. It’s @Luke10. I’m having trouble with The Dunes in Sarven Desert. I got a little help from that tab, but when i ran my code, it said Line 2: TypeError: Can’t read protected property: findNearestItem. I’ve been stuck on this level for a little over a month. Here is my code;

loop:
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if enemy:
        if enemy.type is "sand-yak" or enemy.type is "burl":
            itemPos = item.pos
            itemX = item.x 
            itemY = item.y 
            self.moveXY(itemx, itemy)
            
        if enemy.type is "thrower" or enemy.type is "ogre":
            self.attack(enemy)
            
        elif item:
            itemPos = item.pos
            itemX = item.x 
            itemY = item.y 
            self.moveXY(itemx, itemy)

Any help or suggestions would be greatly appreciated.
Thanks! -@Luke10


#2

I haven’t tried this level yet because it’s subscriber, but here is what I think you should check:

You probably don’t have anything equipped with the findNearestItem() method. Try findNearest(hero.findItems()) instead.

Also revise your use of item.x – that will probably result in an error as well.
You can think of x and y as subsets of pos.

Also try replacing all the self. with hero.


#3

Hey @Luke10
Just finished the same level and was using the same

 itemPos = item.pos
            itemX = item.x 
            itemY = item.y 
            self.moveXY(itemx, itemy)

= no joy/ errors etc. (why does help say the opposite?! docs need fixing)

@zuf
zuf (thanks zuf) Suggested I use:
hero.moveXY(coin.pos.x, coin.pos.y)
= success

That being said, if the hero gets beyond the wall/fence, the hero does NOT return to the gems.
AND, there is some weird lag when a sand-yak or burl walks by… the hero just stops moving (listening ? ;))

hth
Dennis


#4

its cind of hard i know!

but try harder.


#5

Thanks @nina, @pleabargain, @zuf. I will try all of your suggestions.