Ongoing Actions - Walking AND Chewing Gum

I’m trying to make it possible, as the title suggests, to continue to walk while chewing gum (or to continue to watch TV while listening to your spouse, to continue to drive while texting, etc.). Essentially, what I am trying to do below is to allow the user to enter a command like this: “continue walk west” to create a record of an “ongoing action” which will both occur immediately and continue to occur on subsequent turns until the player enters another command like “discontinue walk west” (I haven’t gotten that far yet, still struggling with this first bit). So, then the player can subsequently enter “chew gum”, and both the walking west and chew gum actions will occur that turn.

Of course, it doesn’t work yet, and the biggest problem right out of the gate is that the “player’s-ongoing-action” starts as “waiting” and never changes due to the below code… it is always “waiting”, so the response is always this:

"Time passes

The result of the other action"

The player's-ongoing-action is a stored action that varies.

After reading a command:
	If the player's command includes "continue ":
		cut the matched text;
		now the player's-ongoing-action is the current action;
		continue the action;
	otherwise if the player's command does not include "continue ":
		try the player's-ongoing-action;
		continue the action;

Cool idea! The problem is that at the “after reading command” stage the command has not yet been parsed, so the current action is set to the null value of waiting. You can solve this by using a truth state to keep track of whether you’ve just cut “continue” from your command:

[code]The player’s-ongoing-action is a stored action that varies.
Starting ongoing action is a truth state that varies.

Before reading a command:
now starting ongoing action is false. [This resets the flag every time we read a command.]

After reading a command:
If the player’s command includes "continue ":
cut the matched text;
now starting ongoing action is true;
[continue the action;] [you don’t need this in “after reading a command” rules; as long as you don’t have “reject the player’s command” parsing will continue]

First before when starting ongoing action is true: [this should fire before trying any action whatsoever]
now the player’s-ongoing-action is the current action;
if the current action is not waiting:
say “You begin [the current action] and will continue trying to do so until you specify otherwise.”;
otherwise:
say “Waiting while you do something else is the same thing as doing something else, so we won’t report it.”

Every turn when the player’s-ongoing-action is not waiting and starting ongoing action is false: [we need the second part so we don’t try the action twice on the turn when we start ongoing action]
say “([player’s-ongoing-action])[command clarification break]”;
try the player’s-ongoing-action.[/code]

Now, when we do something that depends on “after reading a command” rules in kludgy fashion like this, they tend to produce bad results when the player enters more than one action with the same command, such as “continue n. w” or even “continue take all”. Our code won’t know not to keep trying all of those actions every turn.

One thing you could try is disabling the continue mechanism when the multiple object list is nonempty or when more than one turn happens in a single command; this thread might give you some ideas for how to do the latter. That’d end up producing awkward results, but could at least allow you to print a failure message that tells the player what happened. (“I’m sorry, I can’t understand ‘continue’ when more than one command has been entered on a line, so I will just try the first action and stop processing.”)

Another thing you could try is a different kludge. Define an NPC, say “continuant,” who is omnipresent (could be part of an omnipresent backdrop). Use the after reading a command to replace “continue” with "continuant, " so that “Continue w” gets turned into “Continuant, w”; namely, a request to continuant to go west. Then redirect any action of continuant’s so that it becomes the player’s-ongoing-action. (Editable Stored Actions by Ron Newcomb would let you do that.) And Bob’s your uncle! [ETA: This thread has more suggestions on how to let the player take over an NPC’s actions.]

By the way, I’d probably use the syntax “begin to walk west,” because it’s more natural (“continue walking west” yields its own set of headaches). And you’d want “stop” and similar things to allow the player to reset the ongoing action. And, as you can see, this probably turns out to be much more complicated than useful. But it’s a cool exercise!

(Another thing you could do is set certain kinds of action – like going, perhaps, but not dropping – so that when the player tried them the game would ask if she wanted to keep doing them. Then you wouldn’t have to worry about parsing.)

…I feel as though it is irresponsible for me to send a newbie haring off after all this esoteric stuff. This is definitely more in the service of tinkering for its own sake rather than getting stuff done. But tinkering is fun!

It would have taken me quite some time to figure out at least one piece of what you demonstrated above (or I would never have figured it out at all). The fact that during the After reading a command there is no current action yet is tricky! Your solution for inserting a truth state immediately before the action can continue is also tricky! Very nice, and thank you again.

I’ll look into expanding this project, of course, but now at least I’m past the first step!

As for this being advanced stuff for a noob, you can read my thoughts on my “projects” below if you want:
[rant]Hoo-boy, yes, some of this is harrowing for a noob, but this kind of thing is the only way I learn, and I feel like I’m learning at a good pace for my way of doing things. See, every time I try something and manage to get it slightly wrong, or every time I ask a question and someone fills in some gaps, I find out about other things, and build a “library” in my mind of related things and tidbits that make sense of things or solve related problems, and see how it all really fits together. Just reading documentation makes me go cross-eyed… I just want to see examples of working code.

For me, this process is not to steal works and “get a fish”, but because I better deconstruct a language in the context of reality than out of a “dictionary” this is actually teaching me to fish and be able to really understand, apply, and build on things. I’d never try to learn to speak a language by reading a dictionary, so I don’t try to learn a programming language that way either. Once I start to get a programming language, I start to think in it “natively”… this makes sense to me anyway, and then later I can look at API documentation and manuals and make sense of things in the “dictionary” because I already know the language, and now am looking up very specific details. Because of this learning style, I’d almost certainly never be able to make my own language up, but I think I can learn a language someone else has made up this way pretty well.

I’ve learned more than one programming language for web development via this method (and while on the job in some cases, talk about stressful). That methodology was easier to do without pestering other people on a forum for more common languages because there are tons of real world examples for solving real world problems. This is a game language, and the problems to solve are very subjective, and the examples a bit abstract.[/rant]

Well, think of it this way: Until we’re done with the after reading a command rules, we don’t know what the command is that we want to translate into an action. There could be more than one after reading a command rule that we need to execute before we’re ready to parse. So it’s too soon for there to be a current action; the current action may depend on some more after reading a command rules.

This chart of the order all the rules run in might help. On the middle left, in the turn sequence rules, you’ll notice that the “parse command” rule is before the “generate action” rule. The “reading a command” activity is at the beginning of the stuff invoked by the parse command rule, at the left of that big purple box. The big purple box is what gives us the current action and passes it on to the generate action rule. (I think.)

I definitely feel what you’re saying about how you learn by tinkering. Though I started by reading the documentation, what has really helped me learn the language is trying to answer people’s questions on the forum.

Remember that if the player types “get gum. chew gum”, the reading-a-command rules run just once, then the action rulebooks cycle twice (including end-of-turn rules).

Yeah, you might want to disallow such syntax. My game The Art of Fugue contains some code that does precisely that; you can find it on the IF Archive. (It is a game that repeats commands, like yours does; or rather, yours repeats actions and mine repeats commands, but this code should work for both.)