Table of Contents

Programming Tutorial VIII - Actions and Passwords

Fun things to do with your guests

In this tutorial we will cover two scenarios that you can present to your guests.

So your room description might describe a guard at the next door, or a rather conspicuous lever in the wall or floor. Only by providing the correct response (word or action) does your guest proceed.

Asking for a password.

Let's tackle the password/puzzle first. That's the easy one.

Set up room A where the puzzle is posed, or at least needs to be answered. Decorated as “Some bloke stands guard at a gate. He fixes you with a steely gaze and asks 'What's the password?'”, or however else you wish to decorate it.

Set up room B: “The bloke breaks into a smile. 'Truly you are wise in the ways of flower arranging. You may enter.'” with a door leading off to where ever you want to have your guest go next.

In room A build a program with an “Exact Match Commentary” Contrivance with the parameter set to your password on the first line, and a “Warp to Room” Contraption with the parameter set to room B on the second. Like this:

 Password correct, engage warp engine.

The first line looks to see if the correct password (or pass phrase) has been typed in. If it has, then the program moves onto the second line and warps the guest to room B. If instead of warping the guest somewhere you want to reveal a page with some information on it, then use a “Show Page” Contraption instead. Or any other Contraption or combination of Contraptions.

What's that? You don't know about 'warping'. Relax, it's just what big time game-designers like you say instead of “taking”. “Take to another room” pffft… anyone could say that!

<note tip>The Match Commentary Contrivance's parameters are not case sensitive, so don't worry about capital letters.</note>

So far so easy. If you've been reading these tutorials through from the start, then you could have quite possibly worked this out for yourself couldn't you? Of course you could. The second task is a little more complicated.

<note tip>Now, before you go charging on, here's a thought: the Contraption that we just used looks for an “Exact” match. Fine for specific passwords, but if you're setting up a puzzle or riddle, you might want to give your guest some leeway. The next section talks about 'Partial' match Contraptions, so you might want to consider using those.</note>

Performing an action.

In the lever example, let's say your that if guest pulls a lever, they get taken to a different room.

This time there're many different things that your guest could type in that you would want to trigger the program. You don't want to build separate programs for absolutely anything that they might try. Here's how to handle the situation. Boil the action down to the bare essentials, often this is a verb and a noun. In this case, the verb is “Pull” and the noun is “Lever”. All you are really interested in is, has your guest typed in something using both of these words?

So instead of using the 'Exact Match Commentary' Contrivance, use the 'Partial Match Commentary' Contrivance. In fact use two of them. Set the first one's parameter to “Pull” and set the other's to “Lever”. Also of course, we will use a Warp Contraption.

For the sake of budding programmers, we will describe this program the opposite way round to usual, as it's on the first line that the interesting behaviour is taking place.

On the second line, put in the 'Warp To Room' Contraption, the resulting action. Then, on the first line put your two 'Partial Match Commentary' Contrivances. Either way round will do. Now click on the knob at the right of the line. Instead of the knob saying “Any” and “Pass”, both on green backgrounds, it should now say “All” on a red background, and “Pass” on a green background. The whole program should now look like this:

 Or, you can use partial matches.

With this program in place, a guest can type “/pull lever”, “/pull the lever”, “/Give the lever a good big pull.” or in fact anything at all that includes the words “Pull” and “Lever”. “/lever existential pull” or even “/Clever flamingoes found pulleys” if they so chose. Fantastic.

<note>Note for budding programmers

The new thing to note here is of course that knob. That's called the flow control knob. Clicking this round has changed how the program flows. Instead of the first line passing if Any of the contrivances on it pass, as happened in the 'Raindrops program in tutorial IV, it now passes only if All of the contrivances on it pass. </note>

Two points to notice.

1) If a line consists of just a single Contrivance, then the two flow control settings aren't terribly different. The line will pass if the Contrivance passes, and fail if it fails. More interestingly…

2) If the line consists of one Contrivance and one Contraption, then with the Flow Control knob set to All Pass, the line should pass precisely when the Contrivance passes, since the Contraption passes automatically. This is in contrast to the Any Pass setting, where a Contraption on a line will cause the line to pass regardless of any other Contrivances that might be on the line, rendering the Contrivances pretty pointless. This can come in useful if you want to have one Contraption work for everybody, and a program which asks just one question. Suppose that your clan HQ has a public garden with gates leading into a clan only area. Then the program in the previous tutorial can be easily modified by putting an extra 'Tree Shadows' Contraption on the first line and setting the Flow Control Knob to All Pass.

However! If you're going to use this trick, then put the Contraption in first before the Contrivance (ie. to the left of the Contrivances). There's a technical reason for this. It's not necessary that you understand the reason, just as long as you remember: <note tip>If there are going to be Contraptions and Contrivances on the same line, then PUT THE CONTRAPTIONS FIRST. </note>

The technical reason is that for some settings of the flow control knob, in particular the All Pass setting, your program gets a little bit clever. It will look along the line, testing each gadget that it finds, until one fails. It knows that if one Contrivance has failed, then they can't possibly all pass, so it doesn't bother looking any further. As a result it won't notice any Contraptions that might be waiting there. To avoid this happening, put your Contraptions first and the Contrivances second.

So we've seen what the Any Pass and the All Pass settings on the Flow Control Knob do, but there're another two settings. The Any Fail, and the All Fail settings. You might be able to guess what these do, but in case you can't, we'll cover them in the next tutorial.


Go to next tutorial.
Return to previous tutorial.
Tutorial Contents Page
Return to Introduction to Programming.
Return to Places Overview