Duplicates of an item - using one of them at a time

I’m having trouble figuring out how to make this work. My goal is to take one detergent pod from the box and put it into the compartment. I want the compartment to be able to hold only detergent pods, and only one at a time. There will be (but I haven’t coded it yet) an action for running the dishwasher, which will result in the detergent pod that was in the compartment being “nowhere.” (If the last detergent pod is being used to run the dishwasher, I’ll make sure the player isn’t put in a situation of needing more.)

I’m starting the scene with ten detergent pods in the box, though, and I think this is where my problem is. I want there to be multiple detergent pods so that the player can run the dishwasher more than once. But Inform doesn’t know which of the ten detergent pods I’m talking about. At least, I think that’s what the error is; I’m very new to this. :laughing:

So here’s my code, and I’m hoping someone can help me figure out how to make it do what I want it to!

A detergent pod is a kind of thing. The description is "Wow, all the dish-cleaning power you need in this one little pod!"

Ten detergent pods are in the box of detergent. 

The compartment is a container in the dishwasher. The carrying capacity of the compartment is 1. The compartment is fixed in place. The compartment is openable. The compartment is open. The description of the compartment is "This looks like the place to put a detergent pod."

Instead of inserting something into the compartment:
	if the player carries the noun and the noun is not a detergent pod:
		say "That's not what belongs here.";
	if the player does not carry the noun:
		say "You don't have that.";
	if the noun is a detergent pod and the player carries a detergent pod and a detergent pod is in the compartment:
		say "There's already a detergent pod in there.";
	if the noun is a detergent pod and the player carries a detergent pod and the compartment contains nothing:
		say "You put the detergent pod into the compartment, which closes automatically.";
		now the player does not carry a detergent pod;
		now a detergent pod is in the compartment;
		now the compartment is closed.
		

And here’s the report Inform gives me:

Problem. You wrote ‘now a detergent pod is in the compartment’: but this is not explicit enough, and should set out definite relationships between specific things, like ‘now the cat is in the bag’, not something more elusive like ‘now the cat is carried by a woman.’ (Which woman? That’s the trouble.)

1 Like

Hi there!

I got it working by changing your last three sentences to these two:


		now the noun is in the compartment;
		now the compartment is closed.

Inform 7 then automatically moves the pod from the players inventory to the compartment, so you do not need to do it in the code. Also, this also works if the player is carrying multiple pods; only one of the pods is then moved to the compartment.

2 Likes

Thank you! That seems so obvious now. :rofl: Appreciate the help!

What might make things a lot easier for you here is, instead of using an Instead rule, you could use a Check, and then an After rule–

Check inserting something into the compartment:
     if the noun is not a detergent pod:
         instead say "That's not what belongs here.";
     if there is something in the compartment:
         instead say "There is already a pod in the compartment."

If you use a Check rule, it will run the action through the Checks already built into the ‘inserting it into’ action, so you will not need to re-write them (whereas an Instead rule would completely bypass them). As Hanon says, no need to re-invent the wheel. This Check rule would occur after those Checks. And if the player has a detergent pod, the ‘inserting it into’ action would be carried through to completion.
Then you could simply write –

After inserting a detergent pod into the compartment:
    say "You put the detergent pod into the compartment, which closes automatically.";
    now the compartment is closed.
3 Likes

Thank you! I’m still trying to learn what exactly the wheels are, so any reinventing is unintentional. :rofl: You’ve helped me understand a bit more about how Inform works! I had figured out how to use checking when defining a new action, but didn’t realize I could use it in the way you describe. There are probably a lot of other places in my code where I’ve done this same sort of thing, but going forward I can use checks and afters rather than insteads.

1 Like

I would strongly encourage using the Index, especially the ‘Actions’ tab–if you click on the ‘Grouped’ tab under ‘Actions’, it will show you the names of all of the built-in actions–all commands understood by the parser map to these actions. You can click on any one of them, and the resulting page will tell you all about that action, what commands are connected to it and what rules govern it.

If you want to create an action, odds are good that there is already an action built-in that you can co-opt to do what you had in mind–it may be that you just need to add a synonym to lead to that action. Just yesterday I implemented a ladder in a game I’m working on. At first, I wanted to create an action so the play could say ‘lean the ladder against [something]’, but then I realized that I could simply have the player be able to say ‘put the ladder on [something]’–because there is already a ‘putting it on’ action–

Understand "lean [something] against/on/onto [something]" or "put [something] against [something] as putting it on.

And as the ladder is long and big, you usually can’t just simply place it on top of most things. This is where an Instead rule is appropriate–because you’re not able to actually put anything on a wall, anyway. What you would do is alter the room description to show the ladder leaning against your wall of choice, or whatever scenery it’s leaning on. Your Instead rule would do these things, in lieu of actually performing the ‘putting it on’ action. You would want it to include all the Checks under the ‘putting it on’ action (not really that many), and then finally the phrases to describe ‘success’(you leaned it against a wall!). You would then want to create a ‘Rule for writing a paragraph about the ladder’ to reflect the ladder leaning against this wall(which one?).

Just an example. You want to economize on creating new actions, so it’s often best to see if the lexicon already includes the action/commands you want.

3 Likes

Actually, scratch that about ‘putting it on’, because I just found out that the ‘pushing it to’ action works much better for a ladder!

1 Like

Thanks for taking the time to write that out, @EpicIFer. I have been using the index to see if there are actions defined for the verbs I’m thinking of already, but I hadn’t really thought about checking for other verbs that might have the effects I want and then adding synonyms.

I have much to learn, and I appreciate the help!

1 Like

Enjoy the journey! You’ll learn a lot just from composing one game. It’s all in the details!

2 Likes

EDIT: Sorry - my messages didn’t load and @EpicIFer pretty much covered it.

Resist the temptation to use INSTEAD for everything that the parser already knows how to do.

Inform’s built in “inserting it into” action already has inherent checks to see if the player is carrying the thing, and the mechanism to actually move it. Instead rules basically shut off the parser and make you do it manually!

Check inserting something into the compartment:
     if the noun is not a detergent pod:
         say "That doesn't belong in there. Try a detergent pod." instead;

Check inserting a detergent pod into the compartment:
     if the compartment contains a detergent pod:
          say "You've already put one in there. Don't waste them - one is plenty." instead;

After inserting a detergent pod into the compartment::
     say "You put the detergent pod into the compartment, which closes automatically.";
     now the compartment is closed.
4 Likes

Thank you @HanonO! You guys are wonderfully helpful.

2 Likes

You could also create:

  1. an object, which is a pod
  2. a number that varies, which is the number of pods remaining in the box

When a pod is taken from the box, decrement the number. If the player tries to take a pod when they already have one or when one is in the compartment, prevent them. When the dishwasher is run, return the pod object to the box.

1 Like

Thanks @KitParsing! I haven’t played around with numbers at all yet…need to explore that. :slight_smile:

1 Like