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))
"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?
Shouldn’t this be “tryImplicitAction(Doff, item)” ?
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.
Ah, I’m being silly. I figured out why. This line of code is within a beforeAction.
I’ll probably add a variable detecting weather or not the object is being checked at the current time that is set before the implicit action is tried.
Although, is there a way to avoid this solution? For example, can I just make an exception and have my implicit not call the before action?
You can do “item.makeWornBy(nil)” instead of doing an implicit action. If you have an inventory weight limit, you’d need to check it manually.
I’ll think about doing that. Thanks for the help.
Is there away to stop implicit action on say a door, where it does not open by itself?