Messing with the Inventory

Hi everyone!

For stylistic reasons, I would like to play with the inventory command a little bit. In my story, the player wears several clothes. In order to make printing the inventory neater, I’d like to break it up into two sections: a “you are carrying:” and a “you are wearing:” section.

I know that I can do this:

Instead of taking inventory:
say “[if the player carries something][We]['re] carrying [a list of things carried by the player][else][We]['re] empty-handed[end if][if the player wears something]. [We] [are] wearing [a list of things worn by the player][end if].”

Unfortunately, that nukes the formatting that prints each item on its own line, which I prefer. Taking inventory with the above code gives this result:

You’re carrying item1, item2, item3, etc. You are wearing clothing1, clothing2, clothing3, etc.

But what I want is this:

You’re carrying:
item1
item2
item3

You’re wearing:
clothing1
clothing2
clothing3

But I don’t even know what to look for in the documentation. I tried searching for “own line” but that didn’t help. Is what I want to do even possible?

Thanks!

This seems to work as far as what you’re asking for–

Instead of taking inventory:
	if the player is carrying something:
		say "You are carrying:";
		let l be the list of things carried by the player;
		repeat with n running through l:
			say "[line break][if n is not proper-named]a [end if][n]";
	otherwise:
		say "You are carrying nothing.";
	if the player is wearing something:
		say "[paragraph break]You are wearing:";
		let l be the list of things worn by the player;
		repeat with n running through l:
			say "[line break][if n is not proper-named]a [end if][n]";
	otherwise:
		say "[paragraph break]You are wearing nothing."

The ‘l’ is a temporary variable used only within the context of the rule (S11.15)
It can be made into a list–which can be numbers, strings, or even in this case, objects (S21.6).
And you can repeat through this list, like you can any other (S21.4).
Of course, always account for the case where the player is carrying nothing, and/or wearing nothing.

You may also want to account for when something that the player has is enclosing something else (when the thing is a container or a portable supporter). So, under the repeat subroutine, aligned with the ‘say’ clause(under both carrying and wearing), you will want to add–

			if there is something enclosed by n:
				let r be the list of things enclosed by n;
				repeat with w running through r:
					say "[line break]	[if w is not proper-named]a [end if][w]";

Same principles, but you will want to use different variables (hence the r and w).

I hope this helps!

1 Like

Of course, you may want something more nuanced–I can refer you to the Recipe Book, S6.7, under the example ‘Equipment List’. I would draw your attention to the last couple of rules under this example, which seem to refer to what you want.

1 Like

Or you could leverage the standard inform lister, if you want to keep indentation etc.

"inventionary" by "Testa"

The hotel hallway is a room. "Bland  as any cheap hotel anywhere."

The player is wearing a zoot suit, a hat and a fancy shirt.

The player is carrying a pepperoni pizza and a tommy gun.

[We first need to get rid of the standard way of listing inventory.]
The print standard inventory rule is not listed in any rulebook.

[Then we substitue our own.]
Carry out taking inventory (this is the list-style inventory rule):
	now everything worn by the player is marked for listing;
	say "You are wearing: [line break]";
	list the contents of the player, listing marked items only, with newlines, indented, with extra indentation;
	now everything worn by the player is not marked for listing;
	now everything carried by the player is marked for listing;
	say "You are carrying: [line break]";
	list the contents of the player, listing marked items only, with newlines, indented, with extra indentation;
				
Test me with "i / drop all / i".

5 Likes

This is manual chapter 11.14, if you were looking.

3 Likes

Also check §21.3. Saying lists of values, and especially the “Oyster Wide Shut” example to learn how to manipulate lists and Inform7 printing methods.

http://inform7.com/book/WI_21_3.html

3 Likes

Thanks everyone! I’m going to give all of your advice a try!

1 Like

I just realized I never commented back on this one. Everyone’s advice was very helpful and I got it working. Thanks again!

2 Likes