Dungeon Arena - Multiple actions


#1

I’m attempting to develop my human battle plan with Hushbaum the librarian. I’m trying to get him to heal his allies if they are hurting, but I get an error: “Only the last action set in chooseAction() will be applied.” This is wonderful, makes me happy, I was assuming that I could only set one action and my code should only ever evaluate to one chooseAction(), but it won’t update and run my new code, or if it does, my friends are still never healed.

Any help?

var regen; regen = False; var friends = this.getFriends(); for (var f in friends) { friend = friends[f]; if (friend.health < friend.maxHealth * 0.5) { this.say("Regenerate, " + friend.id + "!"); this.castRegen(friend); this.say("hi"); regen = True; } } if (!regen) { var enemies = this.getEnemies(); if (enemies.length === 0) return; // Do nothing if all enemies are dead. var enemy = this.getNearest(enemies); this.say("Attack!", { target: enemy }); if (this.canCast('slow', enemy)) { this.castSlow(enemy); // Slow the enemy, or chase if out of range (30m). if (this.distance(enemy) <= 30) { this.say("Not so fast, " + enemy.type + " " + enemy.id); } } else { this.attack(enemy); } }

#2

OK, so I may have caught an issue. I was using False instead of false, maybe that is why the code wasn’t catching that I did only call one action. But I’ve since refactored my code and I can’t test it yet.


#3

Hey,

The issue seems to be with how the compiler reads your code. Your first for loop to check if any friends have health less than half the maxHealth always runs irrespective of what happens. I’m not sure why but the compiler seems to believe that you will have two spells cast in a single frame, one is castRegen and the other would be either castSlow or attack even though your code would only run either the Regen attack or either of the other two by changing the value of the boolean regen. Just putting an if conditional over this.castRegen solves your issue(even though it seems to be correct without it too, imo). Just add an if(regen) statement above this.castRegen(friend) and your code runs fine.

Aditya


#4

True also shouldn’t have a capital letter :smile:

regen= true;