While trying to use “instead” to redirect actions in a sensible way, I’ve noticed that you can do this kind of thing:
Instead of taking the X or the Y or the Z, try taking the A.
but it doesn’t seem possible to do this kind of thing:
Instead of taking or touching or pushing the X, try doing it to the Y.
This isn’t a big deal, since obviously it’s possible to accomplish that in a slightly wordier fashion, although it means it’s a pain to try and redirect “doing anything”. But then I reread the documentation about stored actions and tried this instead:
Instead of taking or touching or pushing the X:
now the noun part of the current action is the Y;
continue the action.
This doesn’t work either, but it made me wonder: can stored actions be modified in this way at all? Or can you store different parts of the stored action separately, so that you have one variable which can refer to “taking” or “jumping” or “pushing it to”, and two variables that can refer to objects, and use them to create a new stored action? Alternatively, is there some kind of hackish thing that would simulate this ability? I can think of some really fun uses for this kind of thing.
It’s certainly possible to hack it in, since a stored action is just a memory structure containing values. The only practical problem is type-safety – the values might be any kind, depending on the action, and you’d have to keep them consistent when you changed them.
I don’t have code for you, though.
Ok, so after some more critical thinking about this, (and playing) it seems like you can at least do the store-separate-variables thing. You apparently can assign an action that normally requires a noun or second noun to a stored action without specifying the noun/second noun (in spite of what the documentation says). Strangely, though, you can only assign it with “now…” - trying to specify a default value results in complaints about trying to change constant values. Anyway, you can then splice in the noun (and presumably the second noun) with the rule for supplying a missing noun.
[code]Test_action is a stored action which varies. When play begins, now test_action is the action of taking.
Testing stored actions is an action applying to nothing. Understand “testaction” as testing stored actions. Instead of testing stored actions: try test_action.
Test_object is a thing which varies. Every turn: now test_object is a random thing in the location; say “test_object is [test_object].”
Rule for supplying a missing noun when the current action is test_action: now the noun is test_object.[/code]
The RFSaMN doesn’t trigger when you just type “take” with no noun, only when you type “testaction”. So you could have variables representing actions without nouns, and variables representing nouns, and combine them every which way and switch them out dynamically. It might be possible to create a fully-modifiable kind to replace the built-in stored action (which has as properties a stored action and two nouns, all variable), but I can’t think of an elegant way to supply missing nouns/etc. with that setup.
(Actually, if inform only understood “Every turn: now test_action is a random action.” you could make a crashme test for IF. I’d never seen the default response for trying to take yourself before.)
There’s an extension called Editable Stored Actions which may be useful to you: inform7.com/extensions/Ron%20New … index.html
Ahh, cool, thanks. I’ll have to play with that.
Does it deal with the type-checking issues zarf mentioned, or is that a caller responsibility? (I’m guessing this is stuff like winding up with nouns that are the wrong types for the action (like setting the action name to GO but the noun to something that’s not a direction) or setting nouns for actions that don’t have nouns, etc.)
Yes, this is very nice; it looks like it could help with a couple things I’ve been playing around with.