? You need to format your code correctly for us to be able to look at your code. So again, please use </> and paste your code.
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
hero.pos.y = #subtract 3 from the hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)
Thanks. Iāll look at it now.
Try to look at this lines, does it seems anything wierd with them?
Andrei
You wrote:
hero.pos.y = #subtract 3 from the hero.pos.y
instead of that, you should type hero.pos.y - 3
Donāt forget to redefine the variable when you do that.
i did it next:`while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
hero.pos.y - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)
`
Also, you wrote
hero.pos.y = #add 3 to hero.pos.y
Instead of #add 3 to hero.pos.y
, add 3 to hero.pos.y by hero.pos.y = hero.pos.y + 3
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
hero.pos.y - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y + 3
pass
hero.moveXY(xPos, yPos)
Does that work for you?
nope not at all i keep dieing
As I said earlier, instead of hero.pos.y - 3
replace it with hero.pos.y = hero.pos.y - 3
.
Also, instead of hero.pos.y + 3
replace it with yPos = hero.pos.y + 3
Oopsā¦ I wasnāt copy pastingā¦ thanks for the reminder!
No problem!
Does this work for you?
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
ypos = hero.pos.y - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
ypos = hero.pos.y + 3
pass
hero.moveXY(xPos, yPos)
```nope
Instead of ypos
, make sure to capitalize it so itās yPos
. This should work.
And if it does, please donāt post solutions. We want other users to learn, not copy and paste off the forum.