You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Freezing then Infinite loop in Sarven Shepherd and Bookkeeper #3709
while True:
# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with: len(enemies)
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
while enemy.health > 0:
hero.attack(enemy)
enemyIndex =+ 1
# Between waves, move back to the center.
hero.moveXY(40, 33)
Code for Bookkeeper (not complete for level goals, but shouldn't freeze and fail):
# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
death = 0
bob = hero.now()
hero.moveXY(58, 33)
while hero.now() - bob < 15:
#hero.say(hero.now() - bob)
enemy = hero.findNearest(hero.findEnemies())
if enemy:
if enemy.health <= 0:
death += 1
if enemy:
hero.attack(enemy)
# Tell Naria how many enemies you defeated.
# I understand the the var bob is the wrong one to say, but I don't think
# that's causing my freezing issue.
hero.say(bob)
# Collect coins until the clock reaches 30 seconds.
# Tell Naria how much gold you collected.
# Fight enemies until the clock reaches 45 seconds.
# Remember to reset the count of defeated enemies!
# Tell Naria how many enemies you defeated.
Figured out that my issue on Sarven Shepherd was trying to increment with enemyIndex =+ 1
I'm going to open another issue as I feel that this should be caught as an error or warning instead of just causing a more obscure infinite loop error.
Haven't yet been able to find my issue on Bookkeeper.
The Bookkeeper bug seems a little weirder.
I rewrote the code to successfully complete the level, however, I have to add a say during the first attack phase to prevent the freezing bug.
The code below freezes and gives an infinite loop error. However, if I uncomment the hero.say("stay down") in line 13 then it works. Somehow the delay from the hero.say is allowing the while loop to exit?
# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
death = 0
bob = hero.now()
hero.moveXY(58, 33)
while hero.now() < 15:
enemy = hero.findNearest(hero.findEnemies())
if enemy:
while enemy.health > 0:
hero.attack(enemy)
death += 1
#hero.say("and stay down")
# Tell Naria how many enemies you defeated.
hero.say(death)
# Collect coins until the clock reaches 30 seconds.
while hero.now() < 30:
coin = hero.findNearest(hero.findItems())
coin_count=0
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
coin_count += 1
# Tell Naria how much gold you collected.
hero.moveXY(58, 33)
hero.say(hero.gold)
# Fight enemies until the clock reaches 45 seconds.
# Remember to reset the count of defeated enemies!
death=0
while hero.now() < 45:
enemy = hero.findNearest(hero.findEnemies())
if enemy:
while enemy.health > 0:
hero.attack(enemy)
death += 1
hero.say("and stay down")
# Tell Naria how many enemies you defeated.
hero.moveXY(58, 33)
hero.say(death)
Activity
alexholman commentedon Jun 3, 2016
Figured out that my issue on Sarven Shepherd was trying to increment with
enemyIndex =+ 1I'm going to open another issue as I feel that this should be caught as an error or warning instead of just causing a more obscure infinite loop error.
Haven't yet been able to find my issue on Bookkeeper.
alexholman commentedon Jun 3, 2016
The Bookkeeper bug seems a little weirder.
I rewrote the code to successfully complete the level, however, I have to add a say during the first attack phase to prevent the freezing bug.
The code below freezes and gives an infinite loop error. However, if I uncomment the hero.say("stay down") in line 13 then it works. Somehow the delay from the hero.say is allowing the while loop to exit?
UltCombo commentedon Jun 25, 2016
That's probably related to (duplicate of?) this issue reported in the forums.