I am trying to teach myself while loops in the cavern survival level.
I was running this code and it hung up with an infinite loop error. It did let me comment out the code. Am I returning out of while loop incorrectly? I figured that placing the instructions for what to do when n>4 on the same indent level as the while loop would work… but I’m working from incomplete knowledge here. I was hoping it would repeat “Done with while loop” while casting shockwave at enemies when the while loop was complete. Advice?
return; // Commented out to stop infinite loop.
return; // Commented out to stop infinite loop.
self.cast("haste", self)
n=0
loop:
while n<5:
# Find and attack the enemy inside a loop.
# Use flags and your special moves to win!
if self.canCast("haste", self):
self.cast("haste", self)
elif enemy:
if self.canCast("root", enemy):
self.cast("root", enemy)
elif self.canCast("slow", enemy):
self.cast("slow", enemy)
else:
n=n+1
if n==0:
if enemy:
self.cast("shockwave", enemy)
if n==1:
self.moveXY(102, 20)
if n==2:
self.moveXY(99, 116)
if n==3:
self.moveXY(146,117)
if n==4:
self.moveXY(147,20)
enemy=self.findNearest(self.findEnemies())
self.say("Done with while loop")
if self.canCast("haste", self):
self.cast("haste", self)
if self.canCast("shockwave", enemy):
self.cast("shockwave", enemy)