What Makes You Tick
Suppose we want to let the player build a fishing pole out of three parts: a hook, a string, and a stick.
There are several things we must account for here. One is that our combination verb should be insensitive to ordering: it shouldn't matter whether the player types COMBINE STICK WITH STRING or COMBINE STRING WITH STICK.
Second, we need to make sure that our implementation handles intervening stages of assembly gracefully. The player should be able to combine string and hook first, or string and stick first, and be able to complete the assembly in either case.
Our implementation here uses a table of lists to determine which combinations of inputs should produce which result object. Because we sort our lists before comparing them, we guarantee that the player's ordering doesn't matter: COMBINE STICK WITH STRING will have the same effect as COMBINE STRING WITH STICK.
What's more, our implementation could be expanded to account for many other assemblages, if we wanted object-building to be a running theme of puzzles in our game.
component list | result |
{stick, string} | hookless fishing pole |
{wire hook, string} | hooked line |
{hooked line, stick} | complete fishing pole |
{hookless fishing pole, wire hook} | complete fishing pole |
Test me with "combine stick with string / i / combine pole with hook / i".
>(Testing.)
>[1] combine stick with string
You now have a hookless fishing pole.
>[2] i
You are carrying:
a hookless fishing pole
a wire hook
>[3] combine pole with hook
You now have a complete fishing pole.
>[4] i
You are carrying:
a complete fishing pole
This kind of implementation makes sense if we don't intend the player to take the fishing pole apart again, or to refer to any of its component parts once it is built. For an alternate approach that does allow assembled objects to be taken apart again, see "Some Assembly Required".