Pizza Prince
Suppose we want the player to have a pizza buffet from which he can take a number of slices. But we don't want to actually put the slices there in front of him, because "you can see 17 slices of pizza here" is not the descriptive effect we want, and because we want to pretend, at least, that the pizza supply is nearly infinite. In fact, we're going to replenish the supply by allowing eaten slices to return to the buffet table (safer in IF than in real life).
To do this, we create one object to stand in for the pizza supply, but whenever the player tries to take it, we give him a different "pizza slice" object instead. Thus:
Now we introduce our actual pizza slices, which are retained in a container out of play until they're needed:
In this example we've set that supply to be artificially small, to make it easier to test what happens when the player reaches the limit; but we could provide many more slices to start with in Pizza Limbo, and the aim in practice would be to pick a number high enough (such as 50 or 100) that the average player will get bored of TAKE PIZZA long before he reaches the limit.
The main thing to be aware of is that objects consume memory in the game file, so creating a large number of pizza slices might bulk the game out. This is more of a concern if we're compiling for the Z-machine than if we're compiling for Glulx.
Whenever the player tries to take the selection, we want him to wind up holding an individual slice instead; but of course we need to check and make sure that he hasn't exhausted the pizza slice supply.
That's fine for the case where the player is taking a new slice of pizza explicitly, but we need to handle it a little differently if the taking action is generated in response to EAT PIZZA. In that case, we need to take the slice and also change the identity of the noun, because after the implicit take action happens, the game will test whether the player is holding the noun before attempting to eat it. So we need to refocus its attention:
And finally, a bit of touch-up:
For tidiness, we should probably also return the consumed pizza slices to Pizza Limbo so that they can be re-used later:
Test me with "i / get pizza / g / i / get pizza / drop pizza / look / get pizza / g / look / eat pizza / g / g / g / g / get pizza / g / g / g / g / g / g / g / g / g / g / g / g / i / eat pizza / take pizza / g".
On the buffet table is a pizza selection. They are all cheese-only, and all luke-warm.
>(Testing.)
>[1] i
You are carrying nothing.
>[2] get pizza
Taken (gingerly).
>[3] g
(from the magnificent selection before you)
Taken (gingerly).
>[4] i
You are carrying:
two pizza slices
>[5] get pizza
(from the magnificent selection before you)
Taken (gingerly).
>[6] drop pizza
(the pizza slice)
Dropped.
>[7] look
Pizza Prince
On the buffet table is a pizza selection. They are all cheese-only, and all luke-warm.
You can also see a pizza slice here.
>[8] get pizza
(the pizza slice)
Taken.
>[9] g
(from the magnificent selection before you)
Taken (gingerly).
>[10] look
Pizza Prince
On the buffet table is a pizza selection. They are all cheese-only, and all luke-warm.
>[11] eat pizza
(the pizza slice)
You eat the pizza slice. Not bad.
>[12] g
(the pizza slice)
You eat the pizza slice. Not bad.
>[13] g
(the pizza slice)
You eat the pizza slice. Not bad.
>[14] g
(the pizza slice)
You eat the pizza slice. Not bad.
>[15] g
That's plainly inedible.
>[16] get pizza
Taken (gingerly).
>[17] g
(from the magnificent selection before you)
Taken (gingerly).
>[18] g
(from the magnificent selection before you)
Taken (gingerly).
>[19] g
(from the magnificent selection before you)
Taken (gingerly).
>[20] g
(from the magnificent selection before you)
Taken (gingerly).
>[21] g
(from the magnificent selection before you)
Taken (gingerly).
>[22] g
(from the magnificent selection before you)
Taken (gingerly).
>[23] g
(from the magnificent selection before you)
Taken (gingerly).
>[24] g
(from the magnificent selection before you)
Taken (gingerly).
>[25] g
(from the magnificent selection before you)
Taken (gingerly).
>[26] g
(from the magnificent selection before you)
"Hey!" barks a hitherto-unseen manager from behind you. "It's an "all you can eat" buffet, not an "all you can stuff down your pants" buffet."
>[27] g
(from the magnificent selection before you)
You are conscious of a disapproving huff from the manager, so you refrain.
>[28] g
(from the magnificent selection before you)
You are conscious of a disapproving huff from the manager, so you refrain.
>[29] i
You are carrying:
ten pizza slices
>[30] eat pizza
(the pizza slice)
You eat the pizza slice. Not bad.
>[31] take pizza
(from the magnificent selection before you)
Taken (gingerly).
>[32] g
(from the magnificent selection before you)
You are conscious of a disapproving huff from the manager, so you refrain.