Switching of arguments for "combine"


I have this problem and I would like to ask for help. Consider this code snippet which is just a silly example:

Combining it with is an action applying to two things.
Understand “combine [something] with [something]” as combining it with.

After combining the water with the newspaper:
say “Bad news… The newspaper is now completely wet.”;
now the water is nowhere; now the newspaper is nowhere; now the player carries the wet newspaper.

But after this the player can only write:
“combine water with newspaper”, not “combine newspaper with water” - I would like to be able to do both to ease the user experience. How can I switch the arguments in a clever way without writing redundant code for each and every combinations possible in the game? It seems there is no boolean, which could do the trick (like an OR) between the two cases.

Two possibilities-

After combining when the current action involves the newspaper and the current action involves the water:

or, even simpler, just have an after rule that tries reversing the noun and the second noun. Then you can just write the condition in one order and if this doesn’t match what the player typed, this rule will automatically try it the other way round:

Last after combining: try combining the second noun with the noun.

Thank you!!! I used the last example and it works on all combinations I have already. :slight_smile:

Just be careful with that to avoid infinite loops, which will occur if both combinations reach that rule.

Hi Juhana

Thanks for the heads up. Do you have an example on something that could trigger this loop? Is it something that can be triggered by the player or just by me coding?


For example if you have this:

There’s a rule to combine water with the newspaper, and the “last after” rule handles combining the newspaper with the water, but there are no rules that would handle combining anything else. So if you combine the water with the carpet, it doesn’t find a rule that matches, it goes to the “last after” rule that tries combining the carpet with the water, doesn’t find a rule that matches, the “last after” rule tries combining the water with the carpet… and so on.

To avoid that you need to make sure that for every combination of every object in the game there’s a rule that matches at least for one order that they can be placed in the action, which is even harder than it might sound. That’s why it’s safer and ultimately easier to use the first option even though it’s a bit more verbose.


Ah. That makes sense. I can see how this can end up in me having to write a bunch of rules to avoid loops with every combination and object involved. I will look at the first option instead. Thank you so much, this way of programming is still so new to me, but this forum and the help here is great!

There is a simple way around this problem (which I had foolishly overlooked), which is to ensure that the rule can only ‘fire’ once each turn:

flipping_nouns_flag is initially false.
Last after combining when flipping_nouns_flag is false:
	now flipping_nouns_flag is true;
	try combining the second noun with the noun;
	now flipping_nouns_flag is false.

This means that the rule is ignored when trying combining reversed nouns, because the flag is now set, and after returning from trying the reversed action the flag is set back to false, ready for the next turn.


That’s neat. TRUE/FALSE variables will come in handy in a lot of cases.

Dr Peter Bates and Juhana have already answered in a more direct and precise way, I’d just like to add that you can also try to handle many of the possible combinations by giving things properties and generalizing over some categories of cases, so that you don’t have to write out all the combinations explicitly.

How you “carve up” the model world with your properties (and/or kinds of things) depends of course on the intended use cases, and on what you want to regard as the default behaviour.

You probably know this already (and you said it was just an example), but I thought I’d post it because it could also be of interest to others who might stumble over the thread.

So, here’s one way of doing it:

The Park is a room.

A thing can be liquid. [By default, it's not liquid.]

A thing can be soluble.

A thing can be spongy.

A thing can be soggy or dry.
Before printing the name of a soggy thing: say "soggy ".
Understand the soggy property as describing a thing.

Definition: a thing is combinable:
	if it is liquid, yes;
	if it is soluble, yes;
	if it is spongy, yes;

The player carries some water. The water is liquid.
The player carries some juice. The juice is liquid.
The player carries a sugarcube. The sugarcube is soluble.
The player carries a newspaper. The newspaper is spongy.
The player carries an absolutely impermeable marble.

Combining it with is an action applying to two things.
Understand "combine [something] with [something]" as combining it with.

Check combining it with:
	if the noun is the second noun:
		say "You can only combine something with something [italic type]different[roman type]." instead;
	otherwise if the noun is liquid and the second noun is liquid:
		say "You don't feel like making a cocktail of [the noun] and [the second noun] at the moment." instead;
	otherwise if the noun is not combinable or the second noun is not combinable:
		say "It seems that no interesting combination can result from these things." instead.

Carry out combining it with:
	if the second noun is liquid:
		try combining the second noun with the noun instead;
	otherwise if the noun is liquid:
		if the second noun is soluble:
			now the second noun is nowhere;
			say "[The second noun] is completely dissolved.";
		otherwise if the second noun is spongy:
			say "[The second noun] soaks up [the noun] like a sponge and is quite soggy now.";
			now the noun is nowhere;
			now the second noun is soggy;
			say "You pour some of [the noun] over [the second noun], but nothing interesting happens.";
		[This covers the case where both categories are combinable in principle, but don't form an interesting combination.]
		say "You fumble around a bit with [the noun] and [the second noun], but you can't see how to make anything interesting happen.".

Test me with "i/combine water with water/combine water with juice/combine water with marble/combine sugarcube with newspaper/combine juice with newspaper/x soggy/combine sugarcube with water/i".

We left the marble totally un-combinable, so it already fails in the check rule, but of course the response from the carry out rule “You pour …” would have been appropriate, too. In the moment, we have nothing in the model world that would trigger the latter response, something that is combinable but doesn’t react with liquids in some way. The exact categorization will depend on what’s most useful for the game.

We could also leave out the “combinable” check and just let everything which we don’t want to customize fall through to the “You fumble around …” response.)

This was quickly thrown together, it’s not super-clean (for example, it mixes model-changes and reports in the carry out rule), and it doesn’t cover everything, but could be helpful, I hope.


Extremely useful, thanks! I have been looking for some way of defining objects in a more generic fashion, also for making weapons etc.