Is there anything wrong with the following code? I got very strange outcomes:
if I comment out the two hero.say statements then I got stuck very early, the system reporting “the code never finished, either it is really slow or infinite loop”
if I leave the first “say” but comment out the second then I got further but eventually the system still reporting “the code never finished…”
if I have all the three say then I get to the end where I “ran out of time” because I spent so much time saying things!
def commandHeal(paladins, target):
for paladin in paladins:
if target.health < target.maxHealth:
if paladin.canCast("heal"):
hero.say(paladin.id + " is healing " + target.id)
hero.command(paladin, "cast", "heal", target)
else:
hero.command(paladin, "shield")
hero.say(paladin.id + " is shielding")
else:
#hero.say("fully healed")
break # previous paladin has fully healed the target
If I remember correctly, there is (was?) an issue with the paladins shielding, but I don’t remember the details… Try to search for “paladin” and “shield” and read a bit around.
On the other hand, if the paladin recently cast heal (cooldown: 0.5 + 5s) then shielded (cooldown: 0.25s) then the next turn(s) he cannot do any of those, so it’s going to be an “empty” loop, which may result in an infinite loop.
@dliang In many of the places that you are using a while loop I would suggest an if-then-else statement instead.
The combat loop, or main loop, is where most of the recursion should occur. Since the code will all execute on the same thread (unlike a pet) having so many loops won’t effectively do what you think they will. Although programmatically the statements may be correct, the game, I believe, is limited to a certain number of loop iterations. This is to prevent code that really doesn’t finish.