Scenes and Moving NPC

I’ve been working on this for at least a week, and I’m hopelessly stuck.

Hodges is a butler, who should come and get you at tea time. You can call him at anytime (which works thanks to StJohnLimbo), and he comes as long as you’re dressed. However, when I try to get him to come up to call you for tea time, he always gets stuck in the DHall. He moves to the Back Parlour just fine though, so I have no idea what is going on.

Here is my latest attempt (using a ridiculously clunky merit badge system that features in a puzzle later). I simplified the world model, but as far as I can tell, there’s nothing in the actual code that triggers any Hodges actions other than these pieces.

[code]Your Room is a room. The description is “Your bedroom.”

The bedroom-door is a door. The bedroom-door is east of Your Room and west of the UHall. Understand “bedroom door” and “door” as bedroom-door. The printed name of bedroom-door is “bedroom door”.

The bedroom window is a door. It is west of Your Room and east of the Gardens.

A closet is in your room. The closet is a openable closed container. A dress is in the closet. A dress is wearable.

The UHall is a room. The description is “A hall upstairs.”

The DHall is a room. The description is “A hall downstairs.” The DHall is below the UHall.

The Gardens is a room. The description is “Gardens”

The Gardens is west of the Front Parlour.

Kitchens is a south of the DHall.

Before going east in the Gardens:
move the player to Front Parlour;
stop the action.

The Back Parlour is south of the Front Parlour. The Front Parlour is west of dhall.

Scullery is south of the kitchens.

Hodges is a man in the Scullery.

The time of day is 8:50 AM.

Chapter 0 - Calling

After reading a command:
if the player’s command includes “[calling]”:
if the player’s command includes “Hodges”:
continue the action;
otherwise:
say “Don’t bother. It’s Hodges’ job to come at your beck and call.” instead.

Understand “call [someone]” and “ring for [someone]” and “ring [someone]” and “call for [someone]” as “[calling]”.

Hodges-calling is an action applying to nothing. Understand “call Hodges” and “Hodges” and “ring” and “call for Hodges” and “ring for Hodges” and “ring up Hodges” and “ring hodges” as hodges-calling.

Hodges can be stationary or called-for. Hodges is stationary.

Carry out Hodges-calling:
if the location of Hodges is not the location of the player:
say “You call for Hodges. Knowing him, he’ll probably be here in a few moments.”;
now Hodges is called-for;
otherwise:
say “‘Yes, Miss Sinclair?’ Hodges says stiffly.”

Every turn:
if Hodges is called-for:
if the location of Hodges is not the location of the player:
let the way be the best route from the location of Hodges to the location of the player, using doors; [*unfortunately this results at times in Hodges jumping out of windows…]
try Hodges going the way;
if the location of Hodges is the location of the player:
now Hodges is stationary.

Check Hodges-calling:
if the player is not wearing the dress:
say “You aren’t inviting Hodges up here half-dressed!” instead.

Chapter 1 - Merit Badges for Hodges

The merit badge of prelude1 is a thing.
The merit badge of prelude2 is a thing.
The merit badge of prelude2-alt is a thing.
The failure badge of prelude is a thing.
The success badge of prelude is a thing.
The merit badge of tea1 is a thing.

Chapter 2 - Fake Hodges Actions

Prelude to Morning Tea is a scene. Prelude to Morning Tea begins when the time of day is 9:00 AM.

Prelude to Morning Tea ends when the player is in the back parlour or the time of day is 9:20 AM.

Morning Tea is a scene. Morning Tea begins when Prelude to Morning Tea ends.

Morning Tea ends when the time of day is 9:30 AM.

Check opening the door:
if the player is not wearing a dress, say “Get dressed first.” instead;

Every turn during prelude to morning tea:
if Hodges does not carry the merit badge of prelude1:
let BP-way be the best route from the location of Hodges to the Back Parlour, using doors;
try Hodges going BP-way;
now Hodges carries merit badge of prelude1;
otherwise:
if the player is wearing the dress:
if Hodges does not carry the merit badge of prelude2:
if Hodges carries the merit badge of prelude2-alt:
stop the action;
otherwise:
if the location of Hodges is not the location of the player:
let the Hodges’s first step be the best route from the location of Hodges to the location of the player, using doors;
try Hodges going the Hodges’s first step;
now Hodges carries the merit badge of prelude2;
otherwise:
now Hodges carries the merit badge of prelude2;
otherwise:
say “[one of]‘Miss Sinclair,’ Hodges says ‘It’s time for morning tea.’[or]Hodges clears his throat, and asks if you are coming to tea.[or]Hodges looks at you rather pointedly. ‘Miss Sinclair, you need to come to tea.’[stopping]”;
otherwise:
if Hodges does not carry the merit badge of prelude2-alt:
let the Hodges’s first trouble be the best route from the location of Hodges to the Uhall, using doors;
try Hodges going the Hodges’s first trouble;
now Hodges carries the merit badge of prelude2-alt;
otherwise:
say “[one of]You can hear a knock at your door and the muffled voice of Hodges calling you. 'Miss Sinclair, it’s time for tea.[or]‘Please, Miss Sinclair. Get dressed and come out.’[or]‘Miss Lisette is waiting for you. Cook’s even prepared a surpise.’[or]You can almost hear Hodges waiting for you to come out.[stopping]”

When prelude to morning tea ends:
remove the merit badge of prelude1 from play;
remove the merit badge of prelude2 from play;
remove the merit badge of prelude2-alt from play;
if Hodges does not carry the failure badge of prelude:
now Hodges carries the success badge of prelude;
otherwise:
continue the action.

[/code]

Thanks for any help.

Could you post a test script that duplicates your problem? I tried waiting for 14 turns and I got:

Hmmm. Using “showme” revealed that even though Hodges is talking to the player, he is still in DHall. I think I see why:

otherwise: if Hodges does not carry the merit badge of prelude2-alt: let the Hodges's first trouble be the best route from the location of Hodges to the Uhall, using doors; try Hodges going the Hodges's first trouble; now Hodges carries the merit badge of prelude2-alt; otherwise: say "[one of]You can hear a knock at your door and the muffled voice of Hodges calling you. 'Miss Sinclair, it's time for tea.[or]'Please, Miss Sinclair. Get dressed and come out.'[or]'Miss Lisette is waiting for you. Cook's even prepared a surpise.'[or]You can almost hear Hodges waiting for you to come out.[stopping]"
The line “now Hodges carries the merit badge of prelude2-alt” does not check whether he’s arrived at his destination yet. You could do that this way:

otherwise: if Hodges is not in the UHall: let the Hodges's first trouble be the best route from the location of Hodges to the Uhall, using doors; try Hodges going the Hodges's first trouble; otherwise: now Hodges carries the merit badge of prelude2-alt; say "[one of]You can hear a knock at your door and the muffled voice of Hodges calling you. 'Miss Sinclair, it's time for tea.[or]'Please, Miss Sinclair. Get dressed and come out.'[or]'Miss Lisette is waiting for you. Cook's even prepared a surpise.'[or]You can almost hear Hodges waiting for you to come out.[stopping]"

But to save yourself and everyone trying to help you some headaches, I think it would help to refactor this into several specific every turn rules, and clean up the merit badge system.

I can’t figure out how to break it up though.

The actions of Hodges should logically go like this:

9:00 AM - Tea Time - Hodges moves to the Back Parlour.
After getting to the Back Parlour -
if the player isn’t there, Hodges goes to fetch the player.
Hodges climbs up to UHALL.
if the player is wearing clothes, Hodges goes in
otherwise Hodges waits outside in UHALL.
The player goes to Back Parlour at Hodges’ prodding.
Tea time.

With the merit badges:
9:00 AM - Tea Time - Hodges moves to the Back Parlour. (Gets prelude1)
After getting to the Back Parlour -
if the player isn’t there, Hodges goes to fetch the player.
Hodges climbs up to UHALL (if the player is in the bedroom).
if the player is wearing clothes, Hodges goes in. (Gets prelude2)
otherwise Hodges waits outside in UHALL. (Gets prelude2-alt)
The player goes to Back Parlour at Hodges’ prodding. (all merit badges are removed from play except for the failure badge if the player doesn’t go to tea; Hodges gets the success badge for later)

I guess my question is how to check if Hodges arrives or not. Also, as far as I can tell Hodges will never get to UHALL for some reason.

I might do it this way - replacing the “stationary”/“called for” property with a “destination” property (if you want Hodges to follow the player if she moves after calling him, you might still need the “called for” property):

[code]Hodges has a room called destination. The destination of Hodges is Scullery.

Every turn when the location of Hodges is not destination:
let way be the best route from the location of Hodges to destination, using doors;
try Hodges going way;

Check Hodges-calling when Hodges is in the location:
say “‘Yes, Miss Sinclair?’ Hodges says stiffly.” instead;

Carry out Hodges-calling:
now the destination of Hodges is the location.

Report Hodges-calling:
say “You call for Hodges. Knowing him, he’ll probably be here in a few moments.”;[/code]

Then I break up your big complicated Prelude to Morning Tea rule into two groups of rules: First, setting Hodges’ destination, and second, what to do when he arrives at his destination.

Full source:

[spoiler][code]Your Room is a room. The description is “Your bedroom.”

The bedroom-door is a door. The bedroom-door is east of Your Room and west of the UHall. Understand “bedroom door” and “door” as bedroom-door. The printed name of bedroom-door is “bedroom door”.

The bedroom window is a door. It is west of Your Room and east of the Gardens.

A closet is in your room. The closet is a openable closed container. A dress is in the closet. A dress is wearable.

The UHall is a room. The description is “A hall upstairs.”

The DHall is a room. The description is “A hall downstairs.” The DHall is below the UHall.

The Gardens is a room. The description is “Gardens”

The Gardens is west of the Front Parlour.

Kitchens is a south of the DHall.

Before going east in the Gardens:
move the player to Front Parlour;
stop the action.

The Back Parlour is south of the Front Parlour. The Front Parlour is west of dhall.

Scullery is south of the kitchens.

Hodges is a man in the Scullery.

The time of day is 8:50 AM.

Chapter 0 - Calling

After reading a command:
if the player’s command includes “[calling]”:
if the player’s command includes “Hodges”:
continue the action;
otherwise:
say “Don’t bother. It’s Hodges’ job to come at your beck and call.” instead.

Understand “call [someone]” and “ring for [someone]” and “ring [someone]” and “call for [someone]” as “[calling]”.

Hodges-calling is an action applying to nothing. Understand “call Hodges” and “Hodges” and “ring” and “call for Hodges” and “ring for Hodges” and “ring up Hodges” and “ring hodges” as hodges-calling.

Hodges has a room called destination. The destination of Hodges is Scullery.

Every turn when the location of Hodges is not the destination of Hodges:
let way be the best route from the location of Hodges to the destination of Hodges, using doors;
[still need to deal with jumping through windows]
try Hodges going way;

Check Hodges-calling when Hodges is in the location:
say “‘Yes, Miss Sinclair?’ Hodges says stiffly.” instead;

Carry out Hodges-calling:
now the destination of Hodges is the location.

Report Hodges-calling:
say “You call for Hodges. Knowing him, he’ll probably be here in a few moments.”;

Check Hodges-calling:
if the player is not wearing the dress:
say “You aren’t inviting Hodges up here half-dressed!” instead.

Chapter 1 - Merit Badges for Hodges

The merit badge of prelude1 is a thing.
The merit badge of prelude2 is a thing.
The merit badge of prelude2-alt is a thing.
The failure badge of prelude is a thing.
The success badge of prelude is a thing.
The merit badge of tea1 is a thing.

Chapter 2 - Fake Hodges Actions

Prelude to Morning Tea is a scene. Prelude to Morning Tea begins when the time of day is 9:00 AM.

Prelude to Morning Tea ends when the player is in the back parlour or the time of day is 9:20 AM.

Morning Tea is a scene. Morning Tea begins when Prelude to Morning Tea ends.

Morning Tea ends when the time of day is 9:30 AM.

Check opening the door:
if the player is not wearing a dress, say “Get dressed first.” instead;

Every turn when Hodges does not carry the merit badge of prelude1 during prelude to morning tea:
Now the destination of Hodges is Back Parlour;

Every turn when Hodges carries the merit badge of prelude1 during prelude to morning tea:
if the player is wearing the dress, now the destination of Hodges is the location;
otherwise now the destination of Hodges is UHall.

Every turn when Hodges is in the destination of Hodges during prelude to morning tea:
if Hodges is in Back Parlour:
now Hodges carries the merit badge of prelude1;
otherwise if Hodges is in the location:
now Hodges carries the merit badge of prelude2;
say “[one of]‘Miss Sinclair,’ Hodges says ‘It’s time for morning tea.’[or]Hodges clears his throat, and asks if you are coming to tea.[or]Hodges looks at you rather pointedly. ‘Miss Sinclair, you need to come to tea.’[stopping]”;
otherwise:
now Hodges carries the merit badge of prelude2-alt;
say “[one of]You can hear a knock at your door and the muffled voice of Hodges calling you. 'Miss Sinclair, it’s time for tea.[or]‘Please, Miss Sinclair. Get dressed and come out.’[or]‘Miss Lisette is waiting for you. Cook’s even prepared a surpise.’[or]You can almost hear Hodges waiting for you to come out.[stopping]”

When prelude to morning tea ends:
remove the merit badge of prelude1 from play;
remove the merit badge of prelude2 from play;
remove the merit badge of prelude2-alt from play;
if Hodges does not carry the failure badge of prelude:
now Hodges carries the success badge of prelude;
otherwise:
continue the action.
[/code][/spoiler]

A reason the original source text didn’t work was this, I suppose:

So, the first turn during the prelude Hodges does not wear the merit badge and therefore moves one room towards the player, whereupon he receives the badge.
The next turn, then, he does carry the merit badge and so starts talking to Miss Sinclair.

You could also award merit badges in an “after Hodges going” (or “last carry out Hodges going”) rule. That would prevent the 1-turn delay that happens because the badge-awarding rules seems to fire before the hodges-going rule.

Thank you so much. I tried to write a code that broke the process into steps, but it, instead of locking Hodges in the DHall, locked him into the Front Parlour.

The called-for action needs some revision in any case. Hodges eventually should go back to where he came from if the player leaves.

Thanks again.

Felix, just before capmikee posted his solution, I fixed my original code for that error, and while Hodges no longer “talks” to the player when he isn’t there, Hodges still doesn’t move upstairs for some reason.

Here is the full adjusted code (that doesn’t work) that takes into account that error. Now Hodges never receives the merit badges (other than the first one for moving to the Back Parlour) since the prerequisite for the others is being in the same place as the player, which he for some reason never fulfills. He just stays in the Front Parlour. I’m not sure why this happens though.

[spoiler][code]Your Room is a room. The description is “Your bedroom.”

The bedroom-door is a door. The bedroom-door is east of Your Room and west of the UHall. Understand “bedroom door” and “door” as bedroom-door. The printed name of bedroom-door is “bedroom door”.

The bedroom window is a door. It is west of Your Room and east of the Gardens.

A closet is in your room. The closet is a openable closed container. A dress is in the closet. A dress is wearable.

The UHall is a room. The description is “A hall upstairs.”

The DHall is a room. The description is “A hall downstairs.” The DHall is below the UHall.

The Gardens is a room. The description is “Gardens”

The Gardens is west of the Front Parlour.

Kitchens is a south of the DHall.

Before going east in the Gardens:
move the player to Front Parlour;
stop the action.

The Back Parlour is south of the Front Parlour. The Front Parlour is west of dhall.

Scullery is south of the kitchens.

Hodges is a man in the Scullery.

The time of day is 8:50 AM.

Chapter 0 - Calling

After reading a command:
if the player’s command includes “[calling]”:
if the player’s command includes “Hodges”:
continue the action;
otherwise:
say “Don’t bother. It’s Hodges’ job to come at your beck and call.” instead.

Understand “call [someone]” and “ring for [someone]” and “ring [someone]” and “call for [someone]” as “[calling]”.

Hodges-calling is an action applying to nothing. Understand “call Hodges” and “Hodges” and “ring” and “call for Hodges” and “ring for Hodges” and “ring up Hodges” and “ring hodges” as hodges-calling.

Hodges can be stationary or called-for. Hodges is stationary.

Carry out Hodges-calling:
if the location of Hodges is not the location of the player:
say “You call for Hodges. Knowing him, he’ll probably be here in a few moments.”;
now Hodges is called-for;
otherwise:
say “‘Yes, Miss Sinclair?’ Hodges says stiffly.”

Every turn:
if Hodges is called-for:
if the location of Hodges is not the location of the player:
let the way be the best route from the location of Hodges to the location of the player, using doors; [*unfortunately this results at times in Hodges jumping out of windows…]
try Hodges going the way;
if the location of Hodges is the location of the player:
now Hodges is stationary.

Check Hodges-calling:
if the player is not wearing the dress:
say “You aren’t inviting Hodges up here half-dressed!” instead.

Chapter 1 - Merit Badges for Hodges

The merit badge of prelude1 is a thing. [aka Hodges goes to the BP sucessfully]
The merit badge of prelude2 is a thing. [aka Hodges goes to where ever the player is successfully]
The merit badge of prelude2-alt is a thing. [aka Hodges goes to Uhall]
The failure badge of prelude is a thing. [aka the player refuses to come to tea]
The success badge of prelude is a thing.
The merit badge of tea1 is a thing.

Chapter 2 - Fake Hodges Actions

Prelude to Morning Tea is a scene. Prelude to Morning Tea begins when the time of day is 9:00 AM.

Prelude to Morning Tea ends when the player is in the back parlour or the time of day is 9:20 AM.

Morning Tea is a scene. Morning Tea begins when Prelude to Morning Tea ends.

Morning Tea ends when the time of day is 9:30 AM.

Every turn during prelude to morning tea: [Hodges going to Back Parlour]
if Hodges is not in the Back Parlour:
let BP-way be the best route from the location of Hodges to the Back Parlour, using doors;
try Hodges going BP-way;
otherwise:
now Hodges carries merit badge of prelude1.

Every turn during prelude to morning tea: [Hodges going to the player]
if Hodges carries the merit badge of prelude1:
if Hodges does not carry the merit badge of prelude2:
if the player is wearing the dress:
let the Hodges’s first step be the best route from the location of Hodges to the location of the player, using doors;
try Hodges going the Hodges’s first step;
if the location of Hodges is the location of the player:
now Hodges carries the merit badge of prelude2;
otherwise:
let the Hodges’s first trouble be the best route from the location of Hodges to the Uhall, using doors;
try Hodges going the Hodges’s first trouble;
if the location of Hodges is Uhall:
now Hodges carries the merit badge of prelude2-alt.

Every turn during prelude to morning tea: [Hodges calling to the player]
if Hodges carries the merit badge of prelude2:
say “[one of]‘Miss Sinclair,’ Hodges says ‘It’s time for morning tea.’[or]Hodges clears his throat, and asks if you are coming to tea.[or]Hodges looks at you rather pointedly. ‘Miss Sinclair, you need to come to tea.’[stopping]”

Every turn during prelude to morning tea: [Hodges calling to the player when player is undressed]
if Hodges carries the merit badge of prelude2-alt:
say “[one of]You can hear a knock at your door and the muffled voice of Hodges calling you. 'Miss Sinclair, it’s time for tea.[or]‘Please, Miss Sinclair. Get dressed and come out.’[or]‘Miss Lisette is waiting for you. Cook’s even prepared a surpise.’[or]You can almost hear Hodges waiting for you to come out.[stopping]”

Every turn:
if the time of day is 9:19 AM:
if the player is not in the Back Parlour:
now Hodges carries the failure badge of prelude;
say “‘Fine, Miss Sinclair. If you insist on missing morning tea, then so be it.’ Hodges says and walks away.’”;
move Hodges to the back parlour.

When prelude to morning tea ends:
remove the merit badge of prelude1 from play;
remove the merit badge of prelude2 from play;
remove the merit badge of prelude2-alt from play;
if Hodges does not carry the failure badge of prelude:
now Hodges carries the success badge of prelude;
otherwise:
continue the action.[/code][/spoiler]

Edit: capmikee, do you mean on your code, or on mine?

Every turn during prelude to morning tea: [Hodges going to Back Parlour] if Hodges is not in the Back Parlour: let BP-way be the best route from the location of Hodges to the Back Parlour, using doors; try Hodges going BP-way; otherwise: now Hodges carries merit badge of prelude1.
Here’s the problem: Hodges is going back to the Back Parlor every turn, even after he has the merit badge and starts moving on. He’s hopping back and forth between Back Parlour and Front Parlour.

Change the rule preamble to this:

Every turn when Hodges does not carry the merit badge of Prelude1 during prelude to morning tea: [Hodges going to Back Parlour]

Here’s a tip: Use some debugging tools. The comments after your rule preambles would make good rule names. Then you could use the “rules” command to see when they’re firing:

Every turn during prelude to morning tea (This is the Hodges going to Back Parlour rule):

And don’t forget the oldest standby of debugging techniques: print statements!

if Hodges is not in the Back Parlour: let BP-way be the best route from the location of Hodges to the Back Parlour, using doors; say "Hodges is not in the Back Parlour. Going [BP-way] from [the location of Hodges]."; try Hodges going BP-way;

If you’re referring to the After going/Last carry out going rule, I meant my code - you don’t really need it if everything’s lumped into one rule. But anything to separate different activities out into separate rules will help make your code easier to read and debug.

I can’t believe I missed that. Thank you for catching it.

Thanks for the tips, especially the rule one, and all the help. I’m still sort of fiddling with the Hodge actions to see which one makes the most sense, and I can see that coming in handy.

No problem. It happens to everyone!

Enjoy!