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 )
onSpawn() is wrong: You hero is told to do different things simultaneously in two places ( the main while loop and onSpawn()). Only the code about the pet must be in onSpawn(). Pets also have a bunch of abilities:
I tried to do what both of you said to, but it doesn’t seem to work for me. I changed my code to:
def onSpawn():
pet.moveXY(28, 110)
while True:
if pet.isReady("shape-shift"): # This is for telling my pet to shape-shift
pet.shapeShift()
enemy = hero.findNearestEnemy()
pet.on("spawn", onSpawn) # This is for my pet to do the function pet
hero.moveXY(93,64)
while True:
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.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)
if hero.time > 120:
break
After that didn’t work, I commented out my onSpawn code, but it still says that it takes too long, or it is an infinite loop. Is there a way to expand the amount of time I can have on this level, like:
That’s probably due the number of ogres getting spawned by your level of Sarven Brawl (quite high I presume).
I’ve got a pretty much invincible (because of the maths of the combo) tactic for Saven Statue (I’m on 10), but I can’t do number 10 because the massive numbers of ogres slow down the level so much it makes an infinite loop. If you don’t want to get a more powerful computer (I’m not sure that would even solve the problem) then you may just have to end Sarven Brawl there.
Reloading the whole page works quite a lot as well. You could also try a different browser. If you’re submitting some successful code don’t skip it or it will make it more likely that it will crash.
Danny
If I’m not mistaken it was MunkeyShynes. But I think Mozilla maybe is good for simulation, but not for replayable levels coding. Besides, does anybody remember the url for ogres, munchkins and so on images?
t̶h̶e̶ ̶p̶a̶r̶a̶m̶e̶t̶e̶r̶ ̶h̶e̶r̶o̶ ̶i̶n̶ ̶b̶o̶t̶h̶ ̶e̶x̶p̶r̶e̶s̶s̶i̶o̶n̶s̶ ̶i̶s̶ ̶a̶l̶s̶o̶ ̶s̶t̶r̶a̶n̶g̶e̶ ̶t̶o̶ ̶m̶e̶ : it’s OK
Running your code I’ve been instantly killed by a sand yak but i didn’t get an infinite loop
Your pet code is OK if you delete
Maybe there is some more things. Try to add one line of moving somewhere at the start. Sometimes it might help. As @xython mentioned your code is qiute fine, so it should work. Unfortunatly I can’t try cause I’m not sub.