Alright. It’s been a while, but I’ve hit a wall with something again. This time it has to do with actions and loops. Specifically, what I want to do is cause an action to be taken for every item in the player’s inventory when a condition is met. The code looks something like this:
foreach(local item in contents)
if(item.ofKind(Armor) && item.isWornBy(self))
{
if(!item.canWearArmor(charArmorSize(item.armorType)))
{
tryImplicitAction(Doff, armor);
"You take off the <<item.name>> due to the heat.";
}
}
If checked that my conditions (namely canWearArmor) work and that the code works without the tryImplicitAction. Yet whenever the implicit action is added, I get a stack overflow when the conditions are met. What am I missing? is this not possible? How else could I achieve what I’m trying to do?
oh, I forgot to change that back when I posted the code. I was trying out something where before the implicit I declared local armor = item. Obviously didn’t work. I just forgot to change it back. Even with item I still get the error.
It should work then. Since it doesn’t, it means the problem is elsewhere in your code. Since you’re getting a stack overflow, it might mean that the code you posted is called again in your Doff handler. So it calls itself over and over again, which is how a stack overflow occurs.
This results in an a stack overflow. The way to solve this depends on the specifics, which I don’t know about here. Usually, it just means you need to introduce a helper method which solves the mutual dependency problem; the two current methods will both call the helper method.