Down in Oodville
Now and then in IF there is a situation where we need to ask the player for a numbered choice rather than an ordinary action command. What's more, that numbered choice might change during the game, so we don't want to just hard-wire the meanings of "1", "2", and "3" whenever the player types them.
A better trick is to keep a list or table (we'll use a table here because it involves slightly less overhead) recording what the player's numerical choices currently mean. Then every time the player selects a number, the table is consulted, and if the number corresponds to something, the player's choice is acted on.
In our example, we'll have a transporter pad that can take the player to any room in the game that he's already visited. (Just for the sake of example, we'll start him off with a few pre-visited rooms.)
transport |
an object |
Test me with "get on pad / 0 / -1 / 8 / 2 / look / w / home / get on pad / get off pad / 3".
The transporter pad in the middle of the floor is currently dull blue: powered but unoccupied.
>(Testing.)
>[1] get on pad
The transporter beeps and glows amber as you step onto its surface. A moment later a hologram displays your options. From here you could choose to go to:
1: Oodville
2: Midnight
>[2] 0
0 is not a valid option. From here you could choose to go to:
1: Oodville
2: Midnight
>[3] -1
-1 is not a valid option. From here you could choose to go to:
1: Oodville
2: Midnight
>[4] 8
8 is not a valid option. From here you could choose to go to:
1: Oodville
2: Midnight
>[5] 2
Midnight
>[6] look
Midnight
>[7] w
Diamond City
>[8] home
Transporter Room
The transporter pad in the middle of the floor is currently dull blue: powered but unoccupied.
>[9] get on pad
The transporter beeps and glows amber as you step onto its surface. A moment later a hologram displays your options. From here you could choose to go to:
1: Oodville
2: Midnight
3: Diamond City
>[10] get off pad
You get off the transporter pad.
Transporter Room
The transporter pad in the middle of the floor is currently dull blue: powered but unoccupied.
>[11] 3
You can transport only from the transporter pad. From other places than the transporter room, you can HOME to your base ship, but not leap sideways to other locations.
If we wanted to replace the regular command structure entirely with numbered menus, or use menus to hold conversation options, we could: several Inform extensions provide these functions.