Pouring something into something else?

So in basic terms, I’m trying to figure out how I can transfer the contents of one container to another without taking them first (for example, a simple way to pour water from vessel to another). There are extremely detailed ways to do this, but I was hoping for a very simple “move contents of the noun to the second noun” sort of action, which would also permit emptying one box of items into another box, amongst other things.

Currently I’ve been working on a pouring into action that will allow you to transfer the contents of the first container to the second (for example, pour the water from the kettle into the mug). So far I can get it to work if I specify the contents (ie: move the water to the second noun), however I would like for this to work regardless of what the contents are. There is also the additional issue of someone saying “pour the water into the mug”, and having Inform not understand that this means the same thing as “pour kettle into the mug”, but idk how to tackle that problem either.

Here’s a simple example of what I can currently get to work.

Sandbox is a room. Description is "A place to test your new rules and actions. Go ahead. Try something!"

The orange table is scenery in Sandbox. The orange table is a supporter. The bottle is a container on the orange table. The cup is a container on the orange table.

A pourable is a kind of container. The bottle is pourable. The cup is pourable.

A liquid is a kind of thing. The fizzy soda is a liquid. The fizzy soda is in the bottle.

Definition: a container is empty if nothing is in it.

Pouring into is an action applying to two things.

Understand "pour [something] into [something]" as pouring into.

Check pouring into:
   if the noun is not a pourable,
      say "That can't be poured.[line break]" instead;
   if the noun is empty,
      say "Nothing falls out.[line break]" instead;
   if the second noun is not a pourable,
      say "You probably shouldn't pour anything in there.[line break]" instead.

Carry out pouring into:
   move the fizzy soda to the second noun;
      say "The [second noun] fills to the brim.[line break]".

Update:

Messing around with this some more, I can change it so that instead of pouring one container into another, I can pour the actual liquid into the second container. However, this still presents the issue of ensuring that the player knows to type out the correct commands. Using this revised code, “pour the soda into the cup” works, but “pour the bottle into the cup” does not. Is there a way to get Inform to understand both commands? New code below:

Sandbox is a room. Description is "A place to test your new rules and actions. Go ahead. Try something!"

The orange table is scenery in Sandbox. The orange table is a supporter. The bottle is a container on the orange table. The cup is a container on the orange table.

A pourable is a kind of container. The bottle is pourable. The cup is pourable.

A liquid is a kind of thing. The fizzy soda is a liquid. The fizzy soda is in the bottle.

Definition: a container is empty if nothing is in it.

Pouring into is an action applying to two things.

Understand "pour [something] into [something]" as pouring into.

Check pouring into:
   if the noun is not a liquid,
      say "That can't be poured.[line break]" instead;
   if the second noun is not a pourable,
      say "You probably shouldn't pour anything in there.[line break]" instead.

Carry out pouring into:
   move the noun to the second noun;
      say "The [second noun] fills to the brim.[line break]".

You may want to check out Emily Short’s “Measured Liquid” extension for ideas, even if it doesn’t apply to what you’re doing outright. I believe you can include it just to handle pouring between vessels, even if you’re not specifically tracking amounts and mixtures.

https://i7el.herokuapp.com/extensions/measured-liquid-by-emily-short
(I imagine there should also be an “official” version of this in the public library within the I7 IDE for download.)

1 Like

One thing you can do is redirect the action in the right circumstances:

Check pouring a pourable into something:
   if the noun contains a liquid (called the drink):
      try pouring the drink into the second noun instead;
   otherwise if the noun contains something (called the solid):
      say "You can't pour out [the solid]." instead;
   otherwise:
      say "[The noun] is empty." instead.

UPDATE: I changed the code because I got mixed up between pourables and liquids. Also, there was an error in my code, but I think it should be fixed by changing your code a little. Namely, you should call your action “pouring it into” rather than just “pouring into”–the “it” lets Inform know where the first noun goes, so you can refer to “pouring a pourable into something” instead of saying “pouring into a pourable something.”

So this is the code I wind up with:

Sandbox is a room. Description is "A place to test your new rules and actions. Go ahead. Try something!"

The orange table is scenery in Sandbox. The orange table is a supporter. The bottle is a container on the orange table. The cup is a container on the orange table.

A pourable is a kind of container. The bottle is pourable. The cup is pourable.

A liquid is a kind of thing. The fizzy soda is a liquid. The fizzy soda is in the bottle.

Definition: a container is empty if nothing is in it.

Pouring it into is an action applying to two things.

Understand "pour [something] into [something]" as pouring it into.

Check pouring into:
	if the noun is not a liquid,
		say "That can't be poured.[line break]" instead;
	 if the second noun is not a pourable,
		say "You probably shouldn't pour anything in there.[line break]" instead.

Carry out pouring into:
	move the noun to the second noun;
	 say "The [second noun] fills to the brim.[line break]".

Check pouring a pourable into something:
	if the noun contains a liquid (called the drink):
		try pouring the drink into the second noun instead;
	otherwise if the noun contains something (called the solid):
		say "You can't pour out [the solid]." instead;
	otherwise:
		say "[The noun] is empty." instead.

yielding these results:

Sandbox
A place to test your new rules and actions. Go ahead. Try something!

On the orange table are a bottle (in which is a fizzy soda) and a cup (empty).

pour table into bottle

That can’t be poured.

pour cup into bottle
The cup is empty.

pour bottle into cup
The cup fills to the brim.

pour bottle into cup
The bottle is empty.

pour cup into bottle
The bottle fills to the brim.

put cup in bottle
(first taking the cup)
You put the cup into the bottle.

pour bottle into cup
The cup fills to the brim.

pour bottle into cup
You can’t pour out the cup.

which is kind of as desired, except there are all sorts of weird things about being able to put the cup into the full bottle and then pour the fizzy from the bottle into the cup. So you might also want to write rules to block that.

(Liquids are notoriously difficult to deal with, because they can get divided and it’s hard to program something in two places at once. If you really want to go hardcore with modeling liquids, definitely have a look at the extension Hanon linked.)

2 Likes

This is super helpful, thank you!!! And yes, the “Measured Liquid” extension is amazing, but I was trying to pare it down into something a little simpler and getting completely lost in the process. I’m not very good/experienced with Inform and get tripped up by little things all the time, so I appreciate the explanations (like, I didn’t even think about “pouring it into” vs “pouring into”, but that makes a lot of sense). Thanks again for the responses!

2 Likes