I7 - Keeping state

Thanks all for helping me so nicely so far.

I’m still trying to implement my first introduction and I can’t figure out how to keep state of the situation. I’ve looked into ‘first day’ example as suggested to me and it will indeed let me run through a set of actions in a predefined order, but that’s not really what I’m looking for. This is the sequence of events I’m trying to make happen and I have no idea where to begin:

How do I make sure that ‘the boss’ goes through a list of annoyed responses if the player doesn’t comply, and how do I make him continue on with the ‘right’ conversation when the player does? I’ve tried adding values to ‘people’ but that seems a little too global to me. Is there a way to keep state of a single scene somehow? Maybe something with tables?

Thank you all so much!

Edit: My ‘too global’ comment wasn’t very clear, this is what I meant: “I can add an ‘introduced’ property to ‘people’ but that means that every NPC in the entire game gets that property just because I want to keep track of whether the player has waved”

The boss can be annoyed or pleased. Every turn when the boss is annoyed: say "The boss [one of]looks at you disapprovingly[or]glares again[or]sighs and taps his watch[or]coughs unsubtly[cycling]."

Thank you, that shows me how I can show the ‘annoyed’ responses. The main problem of getting the boss to move on to his second non-annoyed response after the player complies is still unclear to me. Or is that possible using a similar technique?

You don’t have to worry about the state being too global if the tag is applied to a specific person, like the boss. What you need to do is change that state when the player “waves” – from annoyed to pleased (from Draconis’s example.) This code is not tested (or tabbed correctly!)

After waving at someone (called the subject):
    If the subject is the boss and the boss is annoyed: [only do this when boss is annoyed]
         say "You give a little wave.";
         Now the boss is pleased;
         continue the action; [thanks, Draconis]

Then, once you’ve created the state, add a scene:

boss_leaves is a scene. boss_leaves begins when the boss is pleased and the player is in the location of [whatever location you want] and the boss is in the [location you want].

When boss_leaves begins:
     say "'Excellent. Now that we've all met, I'll leave you with Sarah to sort you out.'"[line break]
The boss leaves in a hurry.";
     Now the boss is in [move to next location].

That scene will only work if the boss is pleased and the player is in a certain location – which should work right after the “wave” command, and only if the boss is annoyed.

Every turn when the Introduction is happening and the boss is pleased: say "[one of]First[or]second[or]third[or]final[stopping] response."

EDIT: Craftian’s method works too, though be sure to put a “continue the action” in your After rule or it will prevent normal action responses from being shown.

Thanks for the suggestions. The [one of] tags are completely new to me!

I still don’t entirely see how I can ‘sync up’ the state if there are more things to say. Would I create a bunch of different values on ‘The boss’ to make this happen? The way I see it I have the following states in my example:

  • Boss is giving his first introduction
  • Boss is waiting for a wave
  • Boss is giving the last part of the introduction

How do I make the boss switched from being pleased to annoyed after saying the fist thing? If I stitch together the various examples here the boss has to start out pleased to say the first thing, but that is also the win condition so I have to make him annoyed first. Or do I just create a set of states:

Lecture is a scene. Lecture begins when play begins.
Lecture ends when the boss is leaving.

The boss is a man in the briefing room.
The boss can be greeting or waiting for a wave or leaving.

Every turn when the boss is greeting during Lecture: 
  say "Welcome... blah blah blah wave plz."; 
  now the boss is waiting for a wave;

After waving hands when the boss is waiting for a wave during Lecture: 
  say "Slightly embarrassed you raise your hand.";
  now the boss is leaving;

Instead of doing anything except waving hands when the boss is waiting for a wave during Lecture:
  say "Something the matter Fred?"

When Lecture ends:
        say "The Boss looks around the briefing room and leaves before you can say anything."
        Now The Boss is nowhere.

Edit: I feel like this is a more generic case of a conversation with only one topic to continue ‘wave’. Is there a system for this?

A few things:

This code is going to end after one turn:

Every turn when the boss is greeting during Lecture: say "Welcome... blah blah blah wave plz."; now the boss is waiting for a wave; [the state's changed, now -- cancel every turn]

You can add some complexity to this function to have different states.

The boss can be annoyed or pleased. The boss is pleased. [start out pleased]

Instead of doing anything except waving hands when the boss is waiting for a wave during Lecture: [here's where you can change the states and have more content] If the boss is pleased: say "Something the matter Fred?"; Now the boss is annoyed; Otherwise if the boss is annoyed: say "Just looking for a hand wave.";

You could expand that otherwise if… code to have more variations. Would this work?

This is something that might be best handled with Scenes, or with Conversation Nodes depending how complex you want to go. How much do you expect the player to do?

In this very specific case not so much, but I’ll have more complicated scenarios that work in a similar vein, where the player will have to perform a specific action until anything progresses. My character is in an apprentice position and the first part of the game is just following instructions and talking to coworkers. There will be a lot of ‘Just put the hose on the widget!’ type stuff.

You could check out the Tutorial Mode extension to see a way of keeping track of actions the player is expected to do. I find it complicated though, and don’t know if it’ll work for what you have in mind.

If the series of tasks is very linear, with only one expected task at any given time, I might do something like this:

[code]The current task is a thing.

The current task can be wave-hand, put-hose-on-widget, switch-on-machine, or none.

The current task is wave-hand.

Instead of waving hands when the current task is wave-hand:
say “You give a little wave.[paragraph break]‘Ok, now put the hose on the widget.’”;
now the current task is put-hose-on-widget.[/code]

But I make no claims as to whether this is the best way to handle it.

After some thought, here’s how I would handle this.

A scene can be nagging. A scene is usually not nagging. A scene has a stored action called the end event.
The scene end flag is initially false.
To decide whether the/an/-- appropriate action is/was/has been/-- performed: decide on the scene end flag.
When a nagging scene ends: now the scene end flag is false.
After doing something when a nagging scene (called the act) is happening:
    if the end event of the act is the current action, now the scene end flag is true;
    continue the action.

[Now once we've written that framework we can do things like this.]
Needing to wave is a nagging scene. The end event of needing to wave is waving hands. [This is the name of the action triggered by the command "wave".] Needing to wave begins when the player is in the Boardroom. Needing to wave ends when the appropriate action has been performed. Every turn when needing to wave is happening: say "The boss [one of]glares[or]looks pointedly[cycling] at you."

Another thing you could do is make a table of the actions that you expect the player to do–though I hit a bug that made this very annoying, or maybe I messed up.

The basic idea is that you have a table that stores the action or actions that the boss wants you to do, as well as some text to print before and after those actions. The game cues up the actions one at a time, erasing the table as it goes; every time you do the right thing it goes on to the next one, and when the table is empty it finishes the scene.

The complication is that sometimes you need more than one action to be acceptable–in particular, when you stand up off the chair, you execute both the action of exiting and the action of getting off the chair, so you want those both to pass. And the bug is that you can’t actually make a preset list of stored actions by writing {exiting, getting off the chair}, so I had to kludge. (I reported the bug.)

Here’s what I got:

[code]Briefing Room is a room. The boss is a man in Briefing Room. The description of the boss is “Like a boss.” Sarah is a woman in Briefing Room. The description of Sarah is “Sarah looks somewhat uncomfortable.” A chair is an enterable supporter in the Briefing Room. The player is on the chair.

Meeting is a scene. Meeting begins when play begins. Meeting ends when time for the boss to leave is true.

When meeting ends:
say “The boss nods and leaves the room.”;
now the boss is nowhere.

The boss can be pleased or annoyed. The boss is pleased.
Every turn when the boss is annoyed: say “The boss [one of]looks at you disapprovingly[or]glares again[or]sighs and taps his watch[or]coughs unsubtly[cycling].”

The actions boss expects is a list of stored actions that varies.
When play begins:
add the action of looking to the actions boss expects. [This cues up the initial looking action, which prints the room description, as an action boss expects, so it doesn’t get blocked by the don’t do the wrong thing rule. We have to cue it up in this roundabout way because we can’t declare the actions boss expects to be {looking} initially because of the bug.]
The reward text is some text that varies.
Time for the boss to leave is a truth state that varies. Time for the boss to leave is initially false.

Every turn when the boss is pleased during Meeting (this is the move on to the next task rule):
if the Table of Boss Expectations is empty: [we’ve done all we need]
now time for the boss to leave is true;
repeat through the Table of Boss Expectations:
add the expected action entry to the actions boss expects;
if there is an introduction entry: [if there isn’t one, then what we have is one of those mostly blank rows that’s being used to build a list of actions for the actions boss expects, so we add it and go on to the next row]
say the introduction entry;
now the reward text is the encouragement entry;
blank out the whole row;
blank out the whole row.

Before doing something when the current action is not listed in the actions boss expects during meeting (this is the don’t do the wrong thing rule):
now the boss is annoyed;
say “Catching a nasty glare from the boss, you decide not to do that.”;
stop the action.

Every turn when the current action is listed in the actions boss expects during meeting (this is the reward correct action rule):
now the boss is pleased;
now the actions boss expects is {};
say the reward text.

The reward correct action rule is listed before the move on to the next task rule in the Every Turn rulebook. [So we print the reward text at the end of the turn and then cue up the next action.]

After looking for the first time: follow the move on to the next task rule. [This cues up the first task after the initial room description is printed, without waiting for a turn.]

Table of Boss Expectations
introduction expected action encouragement
“The boss says, ‘Fred is our new team member. Fred, why don’t you wave?’” waving hands “The boss says, ‘There, that wasn’t so bad.’”
“The boss says, ‘Now let’s our team members familiarize themselves with each other. Sarah, have a look at Fred. Fred, look at Sarah.’” examining Sarah “‘OK, now you know who each other are.’”
– getting off the chair – [This mostly blank row allows us to have both getting off the chair and exiting as acceptable actions for the last step. If I could just put a list of actions in the table, we wouldn’t have to do this.]
“‘Fred, how about you stand up?’” exiting “‘OK then. Seems like you know how to control yourself.’”[/code]

One nice thing is that this can be adapted pretty smoothly to allow multiple such sequences. You can set up a table variable with something like “The instruction table is a table name that varies.” Then you can rewrite all the rules for boss expectations to refer to that variable, and you can trigger a different table whenever you need to. (This will probably take some work to implement.)

Another nice thing is that it’s easy to add to the sequence–just add rows to the table.

I did something like this for the tutorial in one of my games, though there are enough weirdnesses in that that I wouldn’t try to copy it directly–for one thing, it’s entirely about NPC actions.

I really quite like the table approach. I’m going to try it! thank you.