Is there any way to store a phrase in a variable and run it later?
I’m specifically asking about phrases. Not actions. This is all background code, not player commands.
Consider defining custom, high level phrases (with To... :
), and running one inside another:
To throw (item - a thing) at (target - a thing):
[code A]
impact item against target;
[code B]
To impact (item - a thing) against (target - a thing):
...
This code will nest “impact” inside “throw”. Code B in “throw” will be run after “impact”.
Now, for a couple of reasons, I prefer finishing “throw” and running code B before running “impact”. Instead of nesting, if one phrase calls another “custom” phrase , I want to add it to a list of stuff to do, that the engine will do in order.
My current approach is very inelegant. I keep a table with the phrases to run, parameters and order: throw this, impact that, throw something else, etc. Then there is a routine that checks that table and runs whatever it finds there. The ugly thing is that I have to hardcode the references to the phrases in this way:
To perform stuff:
[code reads the table and stores the entries in different variables]
if act is "throw", throw first item at second item;
if act is "impact", impact first item against second item;
Do you think there’s any better way, one that removes such hardcoding?