Inform 7 How to make thing usable

Hey, so I am new to Inform 7 so forgive my newbie-ness.

So I have a sword in one of my rooms (code below) and I want the player to be able to choose to either use this sword on a character (then print some and move the player to a different room) or use it on a animal (then print dialog, give an item to the player, then move the player to a new room). How do I make the sword “usable” in this context? Specifically, I am looking for something along the lines of having the player type “use sword on character” or “use sword on animal”. I might be missing or not understanding a basic feature of Inform 7 that can do this so again apologies!

sword is a thing in The Banquet. The description of sword is “…”.

Inform doesn’t know the command “use” by default so you need to create it.
Then you have to tell inform what action should happen when the player type “use”.
Then you’ll be able to define specific cases for a person or an animal.
Chapter 6 of the documentation will help you a lot. Here’s section 6.2 on creating new commands : Help 6.2

You’ll need to define:

  • a command “use [something] on [something]”
  • a “using” action applying to two things
  • special cases for a sword, a person and an animal (“Carry out using the sword on an animal”, “Carry out using the sword on the chihuahua”…)

Hope this helps!

1 Like

Quite often you’d use a verb other than use (eg hit man with sword, or wave sword at animal). Some of the responses are built in but you can change those.

1 Like

How about something like this:

Lab is a room. 

The sword is here. The description is "A sword.".

Squirrel is an animal in Lab.

Daniel is a man in Lab.

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

Carry out using something on something:
	if the noun is the sword:
		if the player carries the sword:
			if the second noun is the squirrel or the second noun is Daniel:
				say "You hack [the second noun] to bits with the sword.";
				say "You can't attack that with a sword.";
			say "You aren't carrying the sword.";
		say "other instances of using here.".

You might also want to get some responses for “attack”, as Inform knows attacking. So you could also create “carry out” rules for attacking with the sword.


That is perfect! Thank you so much!

1 Like

Hi Daniel,

Welcome to the forum, and Inform! Some good answers here already, thanks to everyone above me. To have your sword respond to commands, you will need to tell Inform about the commands, and define specific behavior for them. These commands and their behaviors are called “actions” in your source text, and vary in their complexity based on how they are designed. An introduction to actions is available in chapter 7 of Writing With Inform, and chapter 12 goes into more advanced techniques.

Every new Inform game begins with a large number of actions already defined, such as looking, taking, examining, opening, etc. One of these built-in actions is attacking. The method which involves the least work is to take advantage of the existing attacking action, and have it check for specific circumstances (i.e. if the player is carrying the sword, if the troll is in the location, etc).

The block attacking rule does nothing if the noun is the troll or the noun is the dude.
[The block attacking rule is a rule built in to the attacking action which does what it sounds like, it disallows violence against other characters or objects. The line above switches off this rule for two characters in the game. "the noun" refers to any potential target of the action.]

Check attacking the troll:
	if the player carries the sword:
		continue the action;
		say "You have nothing to attack that with!" instead.
[This checks if the player has something reasonable to attack with before trying the action. At present it checks only for the specific possession of the sword, but it could check for a kind such as weapon. The logic in this example would be the same for the dude.]

Carry out attacking the troll:
	say "Blam! You absolutely decimate the troll. Well done. You collect a key from its corpse and race onward to...";
	now the player carries the key;
	now the player is in armory.

An alternative to this would be to create a new action called “attacking it with”, if it’s important which weapon the player uses. To get you started, the syntax to create this action and its grammar is:

Attacking it with is an action applying to two things.
Understand "attack [something] with [something]" as attacking it with.

Lastly, your “use” action. As shown above by others, it is possible to create a use action. Personally, I don’t think there’s anything particularly wrong with this, it can save your players a lot of time trying to guess which word to use for whichever item. However, it can be a real headache to implement it, as you will have to define special use behaviors for everything. It can also be somewhat misleading for your players, who may (quite naturally) assume that if every item in your game has a use command, this is the only thing they can do with it. I’m certainly not saying that you can’t have a use action, or that all players will respond to its existence this way. My advice is to be careful with such an action when there are so many alternatives, as it is simultaneously very powerful and very limiting.

EDIT: Added the bit where the player receives the item.


This is very good advice. If you create the USE action like I did, you have to make special responses for EVERYTHING a player could potentially use and EVERYTHING they could potentially use it on. If there are very limited takable, usable things in your game (like only a sword and a magic wand or something like that), then I think a USE command is very friendly. If you have a ton of stuff, then you might get situations where the player tries to USE HAT ON ROCK or USE ME ON CAKE and things like that. Big headache.

ETA: Arthur DiBianca had a game where the only command in the game was USE. I think it was Grandma Bethlinda’s Variety Box? You might want to check that out to see how extensive a USE command can be.