Please paste ALL of your code inside the triple back tick marks.
``` <— Triple back tick marks.
Paste ALL of your code in here.
``` <— Triple back tick marks.
There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.say("My code is formatted properly")
If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.
First, defeat 6 ogres.
# Then collect coins until you have 30 gold.
# This variable is used for counting ogres.
defeatedOgres = 0
# This loop is executed while defeatedOgres is less than 6.
while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say("Ogres!")
# Move to the right side of the map.
hero.moveXY(49, 36)
# This loop is executed while you have less than 30 gold.
while hero.gold < 30:
# Find and collect coins.
targetpos = coin.pos
hero.move(target.pos)
# Remove this say() message.
hero.say("I should gather coins!")
# Move to the exit.
hero.moveXY(76, 32)
“Also conspicuously absent is” a check for enemy health. The counter holds the value of attackedOgres not defeatedOgres If your hero has a simple sword or the enemies are a bit more powerful this will produce an infinite loop.
I don’t understand why I get that error. I reloaded it 20 times; it still gives me that error. How is this fixable? Also I’m using a wizard with a vine staff.