Hi, I have been trying to solve the Sarven Brawl level, and it won’t let me finish because it keeps giving me an error message.
> Your code never finished. It is either slow, or it has an infinite loop.
I am pretty sure that it is the
while true loop that makes it infinite, but before I have used
while true loops and it has always worked. I tried to fix this myself by making the
while true into
while hero.time<=120: but it still gives me the same error message. Could you please help me? Here is my code:
def onSpawn(): pet.moveXY(28, 110) while hero.time<=120: # I'm trying to make it not an infinite loop if pet.isReady("shape-shift"): # This is for telling my pet to shape shift pet.shapeShift() enemy = hero.findNearestEnemy() if hero.gold >=hero.costOf("soldier"): # I am getting some soldiers hero.summon("soldier") for friend in hero.findFriends(): enemy = friend.findNearestEnemy() # The next 4 lines are for commanding my skeletons and soldiers if friend.type=="soldier": hero.command(friend, "defend", hero) if friend.type=="skeleton": hero.command(friend, "defend", hero) pet.on("spawn", onSpawn) # This is for my pet to do the function pet if not hero.hasEffect("invisibility"): if hero.canCast("invisibility", hero): hero.cast("invisibility", hero) hero.moveXY(93,64) while hero.time<=120: # I'm tying to make it not an infinite loop flag = hero.findFlag() enemy = hero.findNearestEnemy() if enemy and enemy.health>0: # I'm cheacking whether I should attack the enemy hero.attack(enemy) if hero.cast("drain-life", enemy): hero.cast("drain-life", enemy) if hero.canCast("poison-cloud", enemy): hero.cast("poison-cloud", enemy) if hero.canCast("summon-undead", hero): # This summons my skeletons hero.cast("summon-undead") if hero.canCast("summon-burl", hero): # Here I'm summoning the burls hero.cast("summon-burl") dead_Corpses = hero.findCorpses() # I'm finding a array of Corpses for dead in dead_Corpses: if dead and hero.canCast("raise-dead"): hero.cast("raise-dead") # RAISE THE DEAD! if hero.canCast("sacrifice"): # This sacrifices my skeletons which I command skeleton = hero.findNearest( hero.findByType( "skeleton" ) ) if skeleton: hero.cast( "sacrifice", skeleton, hero )