Removing "a" or "an" From Inventory List

I know I have seen something concerning this type of issue in the documentation but I will be darned if I can find it again. I want to remove the automatic printing of “a” when the player’s inventory is listed. I am good with NPC inventories because they are completely custom but in lieu of writing new code for the player’s inventory I really just wanted to amend the existing rule if possible.

You are carrying: 
a paper
a personal notepad
a backpack
a leather flake pouch
a reiver blade
a green ribbon
(Health: 100)

I would like to either just list the item or be able to alter how it is listed (ex- “an”, “a pair of”, “some”, etc.).

You can change how a particular object is listed by altering the indefinite article, or just defining it differently in the source code.

The Beach is a room. Some sand is a thing in the Beach. A shovel is a thing in the Beach. A pair of sandals is a thing in the Beach.
Test me with "get all / i".

Removing the article altogether in the inventory listing is a bit more complicated, I’ll post information on that separately.

To change the way the inventory listing as a whole is printed, the best way is to override the rule.

This is the print modified inventory rule:
	say "[We] [are] carrying:[line break]" (A);
	list the contents of the player, with newlines, indented, including contents,
		giving inventory information, suppressing all articles, with extra indentation.

The print modified inventory rule is listed instead of the print standard inventory rule in the carry out taking inventory rulebook.

This is a copy of the “print standard inventory rule” from the Standard Rules, with “suppressing all articles” added to the parameters. You could alter this more to change how the inventory is presented; see WI27.17 for the options available.

1 Like

Check out section 6.7 of the Recipe Book and in particular example 177. This gives you lots of inventory options.

But for stuff like “a pair of” Daniel is right–you probably just want to override the indefinite article there. Often you could just do that the way Daniel did by defining “some sand” (e.g.) in the source text, which sets the indefinite article to “some.” But I think in the case of the sandals you’ll have to set it by hand to get that effect; something like this maybe:

Some sandals are in the beach. The indefinite article of the sandals is "a pair of".

This should get you “a pair of sandals” whenever the indefinite is called for and “some sandals” whenever the definite is (as well as defining the sandals as plural-named, thanks to “some”–if that doesn’t work you might have to set it to plural-named by hand). If you just write “A pair of sandals is in the beach” then I think Inform will define the object as “pair of sandals” with indefinite article “a” which might not be what you want.

For more on articles see section 3.18 of Writing with Inform (which suggests that if you want sand to be singular-named you have to do something slightly different than “some sand”).

Thanks so much for the help all. I could not seem to find it in my searches because I could not remember these were called indefinite articles. Probably bounced all around it before I posted. Awesome, thanks again.

Is there a way to rewrite this on a lower level to prevent articles from being printed only on certain objects (say, ones with a particular property)? We’re writing a custom extension for items with quantities, and we keep getting stuff like “a 2 berries” in the inventory screen.

Yeah, you’d need to go to a lower level for that, since the article printing is handled by the list-writer which is a convoluted piece of code.

Changing the indefinite article property of those particular objects might be easier.

1 Like

One other useful hint I finally learned: if you are tokenizing objects, you can affect whether articles print and how in specific messages by the article you put in the brackets, like [a noun] [the noun] or [noun].

1 Like

This is harder than you might at first think because lots of things you might think of either don’t work at all or don’t fully work.

The difficulty with manipulating the indirect article is:
(i) if the indefinite article ends up printing an empty string, Inform assumes that there is no indefinite article defined and so supplies the standard default ones
(ii) if you get round this by defining the indefinite article as a non-printing unicode character, you will still get a standard space printed after this which messes up the alignment of the inventory
(iii) if you try to get round that by sneakily printing a backspace character to delete said space before printing the name in inventory, you find that the Glk interface that Inform uses for outputting text doesn’t allow output of the backspace character.

The simplest way to suppress indirect articles without resorting to I6 is to make the object proper-named. But we want this to be the case only when printing the name for inventory.

Trying to do this in a Before printing the name of ... when taking inventory: rule doesn’t work because the indefinite article has already been printed by this point.

So:

Lab is a room.

A thing can be definite-inventoried.

The player holds a definite-inventoried thing called a pebble. The player holds a book.

First carry out taking inventory:
	repeat with obj running through definite-inventoried things:
		now obj is proper-named.
	
After taking inventory:
	repeat with obj running through definite-inventoried things:
		now obj is improper-named;
		continue the action.

Any thing can now be switched from being definite-inventoried to not definite-inventoried and back as required.

3 Likes