[SOLVED] Python code error on Thunderhooves

Hi there I got a code error stucking few days on Thunderhooves

My code is like:
while True:
yak = hero.findNearestEnemy()
if yak:
# If yak.pos.y is greater than hero.pos.y
if yak.pos.y > hero.pos.y:
# buildXY a “fence” 10m below the yak.
hero.buildXY(“fence”, yak.pos.x, yak.pos.y - 10)
else:
# buildXY a “fence” 10m above the yak.
hero.buildXY(“fence”, yak.pos.x, yak.pos.y + 10)
pass
else:
# moveXY right 10m towards the oasis.
hero.moveXY(hero.pos.x + 10, hero.pos.y)
pass

I got the python error code:

Line 11: ArgumentError:build’s argument toBuild should have type object, but got string:“fence”. You need a string to build; one of [“bear-trap”]

Any advice for this? Thanks

Hi, welcome to the CodeCombat discourse.
I don’t think you have your hammer equipped. Is that right?
Danny

Thank you Danny you are right I changed hammer instead of sword.

1 Like

Question for the CodeCombat team: does the error message presented by the OP seem correct to you? I was helping my daughter and we got the exact same error text, and unless I’m missing something, it seems totally incorrect. It references a “build” method and states that the argument type should be object, when in fact the method in question is buildXY and the argument type correctly is string. The second sentence (calling for a string) contradicts the first:

Line 11: ArgumentError:build’s argument toBuild should have type object, but got string:“fence”. You need a string to build; one of [“bear-trap”]

This error text was totally unhelpful, given that the issue is needing to equip the hammer.

hello, I need help with this
while True:
yak = hero.findNearestEnemy()
if yak:

    yak.pos.y > hero.pos.y
       
    hero.buildXY("fence", yak.pos.x, yak.pos.y + 10)
    # else: 
    
    yak.pos.y < hero.pos.y
   
    hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
    
else:
   
    hero.moveXY(hero.pos.x + 10, hero.pos.y)
    pass

Is there any problem with my code?

Can you format all of your code as it is described below?

Andrei

yak = hero.findNearestEnemy()
if yak:

    yak.pos.y > hero.pos.y
       
    hero.buildXY("fence", yak.pos.x, yak.pos.y + 10)
    
    
    yak.pos.y < hero.pos.y
   
    hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
    
else:
   
    hero.moveXY(hero.pos.x + 10, hero.pos.y)
    pass
````Preformatted text`

I think you have to write:

if yak.pos.y > hero.pos.y:
1 Like

Hey manes i am stucky on this level of ze codebombat please send codeified help.

# Move right, to the oasis.
# Build a "fence" above or below when you see a yak.

while True:
    yak = hero.findNearestEnemy()
    if yak:
        # If yak.pos.y is greater than hero.pos.y
        if yak.pos.y > hero.pos.y:
            # buildXY a "fence" 10m below the yak.
            hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
        # else: 
        else:
            # buildXY a "fence" 10m above the yak.
            hero.buildXY("fence", yak.pos.x, yak.pos.y + 10)
        pass
    else:
        # moveXY right 10m towards the oasis.
        hero.moveXY(61, 30)

It does not put down the fence and the freaking YAk (That i hate) keeps on ramming me from behind.