I am trying to cast regen on my allied soilders using this bit of code
for(var s in soldiers){
if(this.canCast('regen', soldiers[s]) && soldiers[s].health > 10){
this.castRegen(soldiers[s]);
if(this.canCast('haste', soldiers[s])) this.castHaste(soldiers[s]);
}
}
Where soldiers is an array of allied units of type soldiers. This works great most of the time everyone once in a while it gets stuck on a dead soldier (which is not in the soldiers list) and endlessly case regen it. Also that dead soldier now has full life.
Followup: It seems to happen when she is casting on someone that dies while she is casting