Site Tools
User Tools

Advanced Techniques V - Magic Eight Ball

You know those “Magic Eight Balls” that you can get, where you ask a question, shake the eight ball, and get given one of twenty generic answers? Wouldn't that be a fun toy to install somewhere in your Place? You don't have to keep the same twenty answers, you could have your own. You don't even need to have exactly twenty. You could have as many or as few as you like. You could install one in a bar for example, where the possible answers are “Half a pint of beer.” “One finger of whisky.” and so on. Here's how to do this.

You will need a page for each result that you want to have, decorated with that result. In this example we will assume that there are three different possible results that may be chosen from.

Then you need a Roll to Thought Contraption. These produce random numbers and have three parameters to set. The first two are the minimum and maximum value that you want the random number to be chosen from. We want a number between one and however many answers that you want your Ball to give, in this example three. So set the first parameter to one, and the second to three. You'll notice that it tells you that instead of using numbers, you can use Thoughts instead. Don't worry about this for the time being, stick to numbers.

Lastly, you need somewhere to temporarily store the number that has been randomly generated. This is what Thoughts are for. If you want to understand a little about Thoughts and what they do, then read the Notes for budding programmers below. Here, just pick a name for your Thought. I would use magiceightball, but any name will do. Try to use names which mean something to you and are easy to remember.

IMPORTANT: When naming Thoughts, use only lower case letters. No capital letters, no numerals, no funny symbols or even spaces.

Once your Roll to Thought Contraption has had its parameters set, put it in the top row of your program. Under this use a 'multiple outcomes' type program as has already been gone over in the first and second tutorial. For each possible outcome use a Thought Equal? Contrivance with parameters set to point to the Thought magiceightball and the numbers one, two and three respectively. Again it is possible to use other Thoughts as parameters rather than numbers. Again, don't worry about this yet. Place each of these Contrivances on the left hand side of their own line in the program. Then, taking care that you set the Flow Control Knobs to Any Fail, put Show Page Contraptions in the Escape Hatches, with their parameters pointing to the pages containing your answers.

The whole thing should look like this.

 Using Thoughts to program a magic eight ball.

Note: This program can be considered as a whole gadget in its own right, you may well want to use it from several different rooms. As such it should be put in a hidden room or page somewhere rather than put directly in a room that your guests visit. See the previous advanced programming guide for a discussion of this.

Note: This uses one extra row than is strictly needed. The Roll to Thought Contraption doesn't strictly need its own row, it could be slipped into the first slot of the line below with the Thought Equal to Contrivance directly after it. I've shown it this way to make clearer what is going on.

Note: Now you have built your gadget somewhere, how do you use it? You may wish to have your guest able to use the Eight Ball by using a command, /Eight Ball perhaps. This is easily done, we have covered the Command Contrivances elsewhere. Just use a Commentary Command Contraption with its parameter set to “Eight Ball”, and then on the next line, a Run Program Contraption with parameter pointing to the above program.

More likely you'll want to have a page dedicated to this job so that your guest need only click a link to activate the eight ball. At first sight this seems very easy. Simply build your page, decorate it with an appropriate title (“Use the magic Eight Ball” say) and a blank decoration, then put a Run Program Contraption in a program by itself on this page. However, there's a minor problem here. Once your guest clicks onto this page, this page is where they are until they click elsewhere. If they subsequently start using commands, or RPing with somebody else (or even by themself) then each time they post a comment or use a command, the Eight Ball program will activate again. Ideally you only want it to run when your guest actively clicks on it.

There are ways round this problem, but they're a little too complicated to go into here.1)2) Just be aware that this might happen, and plan accordingly.

Note for budding programmers

Here we have used Thoughts. Thoughts are similar to Memories. They are containers where numbers can be kept. In the above example, the number was a random dice roll used to decide which random effect to show. There are two crucial differences between Thoughts and Memories. First, Thoughts are free. The advantages of this should not need stating. Second, Thoughts only last for one page load. For example, if they are called into existence by a program on a page in a room somewhere, then they will be remembered in that program and any other programs that it calls using a Run Program, they will be remembered in any subsequent programs on that page and any programs run in the room proper. Once this has all happened and control is passed back to your guest however, the Thought will be forgotten. It is temporary.

Note: If a Thought has not been previously set, then it behaves as zero. So if you use a Thought Less Than Contrivance to check if newthought is less than five, where newthought has not previously been mentioned, then this Contrivance will pass. If you use a Thought Greater Contrivance to check if newthought is greater than two, then it will fail.

Thoughts are particularly useful when used in conjunction with Run Program Contraptions as ways of passing information to and from programs. We will start to look at this in the next Advanced Programming Guide, where we expand the above program idea to make a random events table.


Proceed to next tutorial.
Return to previous tutorial.
Advanced Tutorial Contents Page.
Return to Places Overview

1)
The author intends to write a page on how to get round this at some point, but it's low down on his list, which is fairly lengthy. Don't hold your breath. If on the other hand you work out a way round this, then please write a page on it yourself. Remember to put a link in from here.
2)
My money's on a Warp to Room Contraption, but I've been wrong before.
gameplay/guides/places/advtutv.txt · Last modified: 2023/11/21 23:59 by kuhsodas