I7: Creating Generic Items

You can create duplicate items at the start of the game by making a kind and then stating that multiple copies of the item are in a location. From the manual:

[code]A shape is a kind of thing. A square is a kind of shape. A triangle is a kind of shape.

The Geometry Lab is a room. In the Geometry Lab are three triangles and two squares. [/code]

I’m interested in creating items during gameplay. For instance, by using a vending machine the player can get a soda. If he used it 100 times, he’d get 100 identical sodas. I’ve tried this using the following code:

[code]A can is a kind of thing. A soda is a kind of can.

The vending machine is scenery in the cafeteria. It is an open container.

instead of pushing the vending machine:
now a soda is in the vending machine[/code]

This results in the error:

I’ve seen this handled in other games, so I know it’s possible. What am I doing wrong?

In ordinary Inform 7 you can’t create objects during play. Jesse McGrew’s extension Dynamic Objects allows you to do what you want, I think; I’ve never used it but you might want to look at it.

The more common solution is probably to create a bunch of objects offstage and them move them into play one by one as you need them. Example 363 from the manual, Pizza Prince, shows you how to do that. (You have to decide how many cans of soda to create at the beginning, and figure out something to do when the player has taken every single can of soda you created, but your players probably don’t need 100 cans of soda anyway.)

I’m sure the experts will suggest a better way, but I ran into a similar issue not long ago, where I wanted one of two identical items to appear in the game only when the player did something to cause it to appear. My initial attempt was to try to place an unidentified instance of the specified kind offstage ab initio. That didn’t work; evidently Inform 7 let’s you place specific items offstage, but won’t let you do that with an unidentified instance of a kind. What I wound up doing was creating both of the identical items in a particular on-stage location, and moving one of them off-stage in my “when play begins” rule. Unfortunately, that is not likely to work as well where you want the player to be able to “create” an unlimited (or at least very large) number of the items. I suppose you could create 1000 instances of the “soda” kind, place them in a room within the world, and, as part of the “when play begins” rule, keep moving a random soda offstage until there are no more sodas in the room, but it seems a little cumbersome.

Robert Rothman

You probably just didn’t hit the right phrasing. “There are 100 soda cans” creates the items off-stage.

Dynamic Items works perfectly. Now my players drink Dr. Pibb until they’re sick.

If I remember correctly, the problem was that Inform rejects “A soda can is off-stage” (or whatever) when “soda can” is a kind, because it looks like a generic statement about soda cans. But “One soda can is off-stage” creates a single soda can off-stage…

I think “A soda can is off-stage” is exactly what I tried. When that didn’t work, the simple solution of changing “A” to “One” never even occurred to me. Instead I took the complicated approach of putting two soda cans in an onstage location and moving one of them offstage when play begins. Duh! :blush:

Robert Rothman

You could also easily enough create a room called Soda-Can-Heaven and keep the unused items there, instead of “off-stage”.

It’s also worth noting that if you limit the player to five soda cans, it is almost certainly not going to degrade the play experience. Dynamic object creation is rarely needed.

Indeed, there are usually good in-game reasons to limit the player to, say, twenty soda cans. Actual vending machines run out, and all terrestrial species that drink soda can’t hold more than about six cans without a rucksack or other such containing device (and once they empty them and throw them away, you can recycle them back into the the vending machine). Anyway, most players* probably won’t stick around past the first couple of cans unless you’ve given them reason to believe they should. (Yeah, I journeyed to the top of the FrobozzCo headquarters in Zork Zero. What of it?)

*unlike the Cat: youtube.com/watch?v=fPNGaBdHAak