So, I’m new to Python and code combat. I made a combat mechanism for Kithgard Brawl that should work properly, and it does until the loop stops working…
The mechanism is as follows:
# Survive the waves of ogres.
# If you win, the level gets harder, and gives more rewards.
# If you lose, you must wait a day to re-submit.
# Each time you submit gives a new random seed.
loop :
if self.findNearest(self.findItems()) is not None :
potion = self.findNearest(self.findItems())
self.moveXY(potion.pos.x, potion.pos.y)
if(self.findNearest(self.findEnemies()) is not None) :
if(self.isReady("cleave") and len(self.findEnemies()) > 3) :
if self.distanceTo(self.findNearest(self.findEnemies())) > 5 :
self.wait(5)
self.cleave()
elif(self.isReady("bash") and self.findNearest(self.findEnemies()).health) :
self.bash(self.findNearest(self.findEnemies()))
else :
self.attack(self.findNearest(self.findEnemies()))
if self.findNearest(self.findEnemies()) is None :
self.moveXY(40, 34)
In the instance it is now, the loop breaks whenever the hero picks up the potion, but that hasn’t been a problem with the code before. It could also be that it happens the second time it tries to call
self.wait(5)
because that happens immediately after. However, for either scenario, I don’t know how to fix it