[I7] Combining items into a new one

Hi! I’m a total novice to Inform and I just spent close to a full afternoon digging through the documentation and these forums to find out how to perform such a common task in IF - combining/using items together. So I’m sorry if this is really obvious but I can’t really figure it out!

The situation is as follows: I’m trying to setup a very simple puzzle in which the player must combine a rope, a shovel head and a stick to build a makeshift shovel. I’ve been trying lots of combinations, but the latest was:

If the player joins the rope with the stick and the shovel head: say "You join the stick and the shovel head with the rope, making some kind of primitive spade."; the player now carries a spade; remove rope, stick and shovel head from play;

Thank you guys for any assistance! :wink:

(Edited with a better code, last one was very confusing. Still giving me errors though.)

Okay, there is a lot to answer here.

First point: look at the docs to find out what the wording is. You wrote “the player now carries a spade”; it should be “now the player carries a spade”. You may want to be loosey-goosey like that because it’s “English”, but it ain’t English, and you have to be careful about that stuff.

Second: when you’re writing an action rule, it doesn’t begin with “if”. An action rule starts “Instead of ACTIONing…”

Which leads into the third point: you have to know what action you are customizing. There is no “joining” action. If you look through the Index tab, you’ll see a “tying” action, which is closest to what you want. (Verbs for this: “tie”, “fasten”, “attach”.) If the library doesn’t have an action you want, you can define a new one, but in this case it does have one.

Fourth point: Inform generally only handles a verb and two nouns. (There are ways to work around this, but don’t get into it in your first programming exercise, okay?) So let’s simplify this to “attach stick to shovel head”.

The player carries the shovel head.
The player carries the stick.
The spade is a thing.

Instead of tying the stick to the shovel head:
	now the player carries a spade;
	remove the stick from play;
	remove the shovel head from play;
	say "Joined."

This does the fundmentals of what you want.

(Note that “remove rope, stick and shovel head from play” is also a no-no. It’s an understandable mistake, though.)

Now, once you’ve gotten that to work, there will be more to do. This example does not yet handle the reverse form, “attach shovel head to stick”. You might also want to add the synonym “join”. You’d also want to support the command “put shovel head on stick”, which is a different library action. But one step at a time.

Thank you!
After trying that, I’ve been trying to do what you suggested. Got it to work with:

Understand "join [something] to [something]" as tying it to.

Checking the documentation, I also tried to create a new action: “using”, just to check if I could get this to work:

The player carries the stick.
The player carries the rope.
The player carries the shovel head.
The spade is a thing.
Using is an action applying to two visible things.
Understand "use [something] on [something]" as using it on.
Instead of using the stick on the shovel head:
	If the player carries a rope:
		say "You attach the stick to the shovel head using a rope.";
		now the player carries a spade;
		remove the rope from play;
		remove the stick from play;
		remove the shovel head from play.

It just gives me a blank response when I try it, though.

In this case it’s as simple as

Understand the command "join" as "tie".

But I see no reason why the latter line (“tying it to”) would not work.

It did, sorry, I edited the above post since I realized that, it was just a typo on my source at the time.

Alright, tried again, this time using the check and report:

Check using:
	if the noun is not carried:
		say "Try picking it up first." instead.
Report using:
	say "That does not have any visible results.".
Instead of using the stick on the shovel head:
	If the player carries a rope:
		say "You attach the stick to the shovel head using a rope.";
		now the player carries a spade;
		remove the rope from play;
		remove the stick from play;
		remove the shovel head from play.

It doesn’t seem to get past the instead though, since:

use stick on shovel head
gives me “That does not have any visible results.”

Since Instead rules result in failure, they prevent subsequent rules (such as Report rules) from firing. That’s in keeping with the purpose of the Instead rules, which is to handle exceptions to normal behavior.

Hum, from what I understand, that’s what I tried to do: make the normal behaviour for the “use” command to do nothing, save for the exceptions where I use the instead. The problem seems to be the opposite: the report is firing first, and the instead never happens.

My bad, I misread what you wrote.

Home is a room.
The stick, the shovel head, the spade and the rope are here.

Using it on is an action applying to two things.
Understand "use [something] on [something]" as using it on.


Check using when the noun is not carried: say "Try picking it up first." instead.
Report using: say "That does not have any visible results."

Instead of using the stick on the shovel head when the player carries a rope:
	say "You attach the stick to the shovel head using a rope.";
	now the player carries a spade;
	remove the rope from play;
	remove the stick from play;
	remove the shovel head from play.

I tried to reproduce the error you mentioned, unsuccessfully. The above code seems to work as you intended, and also gets rid of the annoying bug if the player does not carry the rope. Conceptually, the Report rules tend to be used for successful actions, so you may want to change it to another Check rule instead.

Thank you! Your code works great. Didn’t know you could define conditions for the insteads that way, I think that’ll make what I have in mind much easier to implement.

It’s a pretty neat way to impose conditions on rules, but I’ve found it takes a while for new authors to become comfortable with its quirks. Stick with it for a while and you should be fine.

You’ll also need to make sure that this action is symmetrical about the noun and the second noun so that “tie shovel head to stick” does exactly the same thing as “tie stick to shovel head”.

You may also want to take a look at “Example 416 - What Makes You Tick” in The Inform Documentation as it has a good way of implementing this.

Hope this helps.

Good point. For a simple one-off action, where a table-based solution may be overkill, one can also do that just by adding a rule for all the “reversed” combinations like this:

Instead of tying the shovel head to the stick: try tying the stick to the shovel head.