Check rules at war

It seems as if my code should work, but apparently two check rules are at war:

[code]Check squeezing tube of toothpaste:
say “You squeeze a bit of toothpaste onto the brush.”;
now squiggle of toothpaste is on toothbrush;
continue the action.

Check squeezing tube of toothpaste:
Check brushing teeth:
if squiggle of toothpaste is not on toothbrush:
say “You need to put some toothpaste onto the brush first.”;
stop the action.[/code]

I tell the parser to “brush teeth” and it tells me back both success and failure: “Your pearly whites just got whiter.”

AND

“You need to put some toothpaste onto the brush first.”

Just tried it again. It appears the problem is in the Check squeezing tube of toothpaste rule: parser says the squiggle of toothpaste is now on the toothbrush, but “actions” reports failure. So I can fail and still clean my pearly whites.

You can’t put a rule preamble inside the body of a rule. The preamble can either be “Check squeezing tube of toothpaste” or “Check brushing teeth”, not both.

I think you’re having trouble with stopping the action at appropriate times. Here’s some sample code:

[code]“Brushing Teeth”

The Bathroom is a room. “This is a spartan, but functional half-bathroom. You see a grimy sink in one corner with a toilet next to it.”

The sink is in the bathroom. On it is a tube of toothpaste and a toothbrush. The sink is fixed in place and scenery. “A porcelain pedestal sink that is probably supposed to be white, but has been turned a dull grey by a thick layer of tacky grime.”

Understand “brush” as toothbrush. The toothbrush is either empty or full. The toothbrush is empty. The description of the toothbrush is “This well-used toothbrush is a nest of matted, bent bristles with bits of goo mashed in between. But it’s the only one you have. [if full]There is a small squiggle of toothpaste on the brush.”

The description of the tube is “The tube of toothpaste is completely white and curled up like a snail’s shell. If you squeeze hard, you can probably get one last brushing out of it.”

Understand “teeth” as yourself.

Check squeezing tube of toothpaste:
if the player does not carry the toothbrush:
say “Squeezeing toothpaste onto the floor would just make a mess.”;
stop the action.

Carry out squeezing the tube of toothpaste:
now the toothbrush is full.

Report squeezing the tube of toothpaste:
say “You squeeze a bit of toothpaste onto the brush.”;
stop the action.

Brushing is an action applying to one thing. Understand “brush [something]” as brushing.

Report brushing: say “I don’t know how to brush that.”

Check brushing yourself:
if the player does not carry the toothbrush:
say “You can’t brush your teeth without a toothbrush.”;
stop the action;
if the toothbrush is empty:
say “You need to put some toothpaste on the brush first.”;
stop the action.

Report brushing yourself:
say “Your pearly whites just got whiter.”;
stop the action.

test me with “brush teeth / get tube / squeeze tube / get brush / brush teeth / x brush / squeeze tube / x brush / brush teeth”.[/code]

I’m getting the phenomena of failing and succeeding at the same time.

The rewritten code:

Check brushing teeth: if player does not hold toothbrush: say "You need a toothbrush for that."; stop the action; otherwise: if player does not hold tube of toothpaste: say "You need toothpaste for that."; stop the action; otherwise: if squiggle of toothpaste is not on toothbrush: say "You need to put some toothpaste onto the brush first."; stop the action; otherwise: say "Your pearly whites just got whiter."; continue the action.

And associated code:

The toothbrush is a thing. It is on the sink.

I think my problem lies in not describing the toothbrush as a supporter, but when I did that before, it didn’t work.

How do you have “brushing” defined?

Brushing is an action applying to one visible thing.

Check brushing teeth: if player does not hold toothbrush: say "You need a toothbrush for that."; stop the action; otherwise: if player does not hold tube of toothpaste: say "You need toothpaste for that."; stop the action; otherwise: if squiggle of toothpaste is not on toothbrush: say "You need to put some toothpaste onto the brush first."; stop the action; otherwise: say "Your perly whites just got whiter."; continue the action.

Can you turn actions on again, and cut and paste the problematic output?

Bath
All the modern conveniences are here, or at least as many as you can afford, which ain’t much.

You can see a sink (on which are Burma-Shave, a razor, a toothbrush, a tube of toothpaste and a comb) here.

What’s the plan, Stan?

take tube
Taken.

There’s no dice in this game. MOVE!

remove cap from tube
You take the cap from the tube of toothpaste.

What’re you gonna do next, boss?

drop cap
Dropped.

What ya gonna do now? Ride a bicycle?

take toothbrush
Taken.

This ain’t no parking lot. Get a MOVE on!

actions
Actions listing on.

squeeze tube
[squeezing the tube of toothpaste]
You squeeze a bit of toothpaste onto the brush.

You achieve nothing by this.
[squeezing the tube of toothpaste - succeeded]

Spill it, buddy.

brush teeth
[brushing Teeth]
You need to put some toothpaste onto the brush first.
[brushing Teeth - failed the Check brushing teeth]

Like, what’s next, man?

i
[taking inventory]
You are carrying:
a toothbrush
a tube of toothpaste

[taking inventory - succeeded]

One o’clock, two o’clock, three o’clock – Do somethin’, man!

squeeze tube
[squeezing the tube of toothpaste]
You squeeze a bit of toothpaste onto the brush.

You achieve nothing by this.
[squeezing the tube of toothpaste - succeeded]

I can see two things at least:

  1. Your squeezing check should be stopping the action sometime after the “check” rule completes. The message “You achieve nothing by this.” is because squeezing is continuing and falling through to the default message.

  2. Your toothpaste is not on the brush, which is probably why the brush check is failing.

There are a bunch of problems with having an object called “squiggle of toothpaste” that you put on the toothbrush: a) You have to make the toothbrush a supporter, which means you have to add a “putting on” rule so that you don’t, for instance, get the player putting a towel on the toothbrush or something. b) You have to create the squiggle object at game beginning, put it out of play, bring it into play (move it) via the squeezing rule, then take it back out of play after brushing. c) You have to deal with the player trying to grab the squiggle and put it other places.

It’s probably simpler to do it the way I did in the code above: give the toothbrush an empty/full property and alter its description based on the state of that property. Then your squeezing rule can just set the toothbrush to full and you can do a check on that for the brushing rule. You don’t have to deal with all the other stuff because the empty/full property only applies to the toothbrush.

An aside: I really like the use of random(?) prompts to create a sense of urgency in the player. Nice effect!

Really? If I were playing this game, I’d find that incredibly annoying. Just reading it is annoying. I’d stop playing after about five turns, and never launch the game again. (But bear in mind, I may not be a typical player!)

Yes, random, and thank you.

Thanks for your very helpful comments, Matt_W. The rewritten code works.