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”]
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.
# 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)