[I7] accessing actions lower down in the stack

So, there are occasions where, during the processing of an action, I might want to call another action.

[code]Test Chamber is a room.

Carry out jumping:
try waving hands.

Carry out waving hands:
try thinking.[/code]

Is there any way in Inform to determine what the “calling” action was? That is – during action (2), I might want to know what action (1) or action (0) was. Basically, I want to be able to look at actions further down in the stack. Like,

Instead of thinking when the calling action is eating: say "Can't think -- eating."

(That’s a pretty stupid example – I promise I do have a more interesting application in mind.)

Is that information stored anywhere accessible?

No, it’s buried on the stack.

You could write a “before doing anything” rule to add action information to a list. Cleaning it up is going to be a pain, though.

You probably won’t need to do this very often though, so you could use a variable to manually track when you are using try.

[code]Currently jumping is a truth state variable.

Carry out jumping:
now currently jumping is true;
try waving hands;
now currently jumping is false;[/code]

That’s what I ended up doing, more or less.

I’m not sure how fail-proof this solution is, but this is what I’m working with:

[code]A person has a list of stored actions called myActions.

First before an actor doing anything when the actor is a person (this is the add current action to myactions list rule):
add current action to myActions of the actor;

First after an actor doing anything when the actor is a person (this is the remove current action from myactions list rule):
truncate myActions of the actor to ((number of entries in myActions of the actor) - 1) entries;
continue the action;

This will create a stack of actions being done by a person. You can easily alter it to work for things or whatever kind you need to track actions for, mine works for people because that’s all I needed it to.

Here’s an example of how to access the current action:

To decide which stored action is the/-- current action for (p - a person): let entries be number of entries in MyActions of p; if entries is not 0, decide on entry entries of myActions of p;

Likewise, you can access the whole stack to search for other actions, if that changes anything. You can compare them to “the action of taking the lamp” and stuff…

Also of note that unless you do something to the way actions are processed, actions will get finished one after the other and then the stack will be empty, so if you check for it in “Every turn” rules, it will be empty, as the “current action” has long since finished! So this only works if you’re going to have a rule for the created action, for instance, that checks which action generated it, as by that point it has not yet finished.

(I am using the latest inform version, I think it had some major improvements with stored actions, so this probably doesn’t work with older versions)

Any check rule that interrupts the action will never reach the “after” stage. So your setup will leak stack entries pretty seriously. (This is why I said cleaning it up is a pain.)