Hi everyone. So I thought I had solved the level “The one wizard”. Ran the code, killed all the bad guys and everything. Then I tidied up my code by removing some hero.say statements that I had put in for de-bugging. Now the code won’t run through, and I can’t figure out why. What’s worse is it freezes at different points, so I can’t identify the problematic bit of code.
# Defeat as many ogres as you can. # Use 'cast' and 'canCast' for spells. enemy = hero.findNearestEnemy() while True: while enemy: #while there are enemies if enemy.type == "ogre": hero.moveXY(5, 31) else: if hero.distanceTo(enemy) > 30: #if it's beyond wand range cast litng-bolt if hero.canCast("lightning-bolt", enemy): hero.cast("lightning-bolt", enemy) else: # otherwise use chain-lightning if it's ready if hero.canCast("chain-lightning", enemy): hero.cast("chain-lightning", enemy) else: # otherwise use your wand hero.attack(enemy) enemy = hero.findNearestEnemy() # check if there are any more enemies if hero.canCast("regen", hero): # if there are no enemies, cast regen hero.cast("regen", hero) enemy = hero.findNearestEnemy() #check again for new enemies