When I run the code, my player kills the ogres, but when he moves to the right side of the map he just stops in the middle. An X pops up and I get the error “Statement execution limit reached”. I am sort of young and started about a month ago, so I could just be doing something wrong.
Here’s my code:
# First, defeat 6 ogres.
# Then collect coins until you have 30 gold.
item = hero.findItems()
# 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.
if item.type == "coin":
hero.moveXY(item.pos.x, item.pos.y)
# Remove this say() message.
# Move to the exit.
hero.moveXY(76, 32)
I found another post for Double Cheek that was solved and followed their code (I fixed the problem with it) but the same problem happened. My player just stopped in the middle, and I have no idea what’s wrong.
#First, defeat 6 ogres.
# Then collect coins until you have 30 gold.
item = hero.findNearestItem()
# 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.
if item:
hero.moveXY(item.pos.x, item.pos.y)
# Remove this say() message.
# Move to the exit.
hero.moveXY(76, 32)
But I still get the error “Statement execution limit reached” on hero.moveXY(49, 36)
Is there an error that I haven’t fixed?
The error is in the second while loop. Currently, it is an infinite loop since you won’t find an item while in that loop. Since you don’t find an item, you can’t pick it up and you don’t increase your gold.
I see you have the needed code, it’s just in the wrong spot.