[SOLVED] Help: Sarven Desert > Thunderhooves

Language: python
can you correct me to get through this level? hero doesn’t move after building the fence

while True:
    yak = hero.findNearestEnemy()
    if yak:
        if yak.pos.y > hero.pos.y:
            hero.buildXY("bear-trap", yak.pos.x, yak.pos.y - 10)
        else:
            hero.buildXY("bear-trap", yak.pos.x, yak.pos.y + 10)
    else:
        hero.moveXY(hero.pos.x + 5, hero.pos.y)

However, I got it working with this (dirty) code

while True:
    yak = hero.findNearestEnemy()
    if yak:
        if yak.pos.y > hero.pos.y:
            posx = hero.pos.x
            posy = hero.pos.y
            hero.buildXY("bear-trap", yak.pos.x, yak.pos.y - 10)
            hero.moveXY(posx+5, posy)
        else:
            posx = hero.pos.x
            posy = hero.pos.y
            hero.buildXY("bear-trap", yak.pos.x, yak.pos.y + 10)
            hero.moveXY(posx+5, posy)
    else:
        hero.moveXY(hero.pos.x + 5, hero.pos.y)

You are supposed to be building a fence not a bear-trap.

1 Like

Hello and welcome to codecombat discourse @rskabilan ! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Yes, that's correct, it should be all.

@rskabilan you have to equip Crude or Wooden hammer

Welcome!! Even if thats dirty code and it works please delete it.

I can’t use fence, it throws me an error: “ArgumentError: build’s argument to Build should have type object, but got string: “fence” You need a string to build; one of [“bear-trap”]”

Excellent that I solved the problem! thank you

The only problems with your code is your supposed to build fences and the move is supposed to be ten beters.

I marked the title as “solved”, should I still delete this discussion?

Nah, you can keep it, just mark the little tickbox to the post that helped you complete the level and it will close automaticly.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.