Can anybody please explain why my code doesn’t work for this level. Also, by the way whatever I do, I am unable to get my indentations to turn blue? Any help please?
while True:
enemy = hero.findNearestEnemy()
if enemy:
if not enemy.type is "peon":
hero.attack(enemy)
item = hero.findNearestItem()
if item:
itemx = item.Pos x
itemy = item.Pos y
if item.type != "poison":
hero.moveXY(itemx, itemy)
Thank you, it worked. So for future reference, locating an item without it’s specific coordinates I would use code with the format of “name.pos.x , name.pos.y”?
@jackattack825 If I understand you correctly. You are asking if one doesn’t receive actual coordinates of an item in the form x = 30 and y = 45 can you use “name.pos.x” to find its x coordinate?
Yes.
As long as that game piece has a “pos” attribute. For instance the Hero has a “pos” enemies have a “pos”, doors may have a “pos”. The game should throw an error if the game piece doesn’t have a “pos” and you type “name.pos.x”.
Friends, Enemies, and items should generally have a “pos” And everything that has a “pos” has an “x” and “y” component.
I ran your code and it worked perfectly fine. Have you let it run all the way through? If there is a peon it goes and gets the poison and dies but if not you attack then go get coins.
Help! My code is didn’t work. Maybe it’s a bug?
while True:
enemy = hero.findNearestEnemy()
if enemy:
if enemy.type != “peon”:
hero.attack(enemy)
item = hero.findNearestItem()
if item:
# Собери предмет только если тип (type) не равен “poison”.
if item.type != “poison”:
pos = item.pos
x = pos.x
y = pos.y
hero.moveXY(x, y)
pass
I have the same problem, I can’t get past Useful Competitors level, and I have tried both Python and JavaScript.
My Python looks like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
if not enemy.type is "peon":
hero.attack(enemy)
item = hero.findNearestItem()
if item:
itemx = item.pos.x
itemy = item.pos.y
if item.type != "poison":
hero.moveXY(itemx, itemy)
I can defeat all the enemies but I’m left with one gem every time.
I used the same code as s1mpsonn in the beginning, and that didn’t work either.
Here is my code.
while True:
enemy = hero.findNearestEnemy()
if enemy:
if not enemy.type is “peon”:
hero.attack(enemy)
item = hero.findNearestItem()
if item:
itemx = item.pos.x
itemy = item.pos.y
if item.type != “poison”:
hero.moveXY(itemx, itemy)