Site Tools
User Tools

Advanced Techniques VI - Random Events

So you'd like to have random events in your place. Things a bit like Crazy Audrey say. Some sort of NPC that turns up from time to time, or other flavour text that pops up at random intervals. Perhaps you want random events which are more exotic, improbable, swarms of butterflies suddenly appearing, glowing green clouds that seem to come from nowhere, maybe even have honest politicians showing up. Here we show a modification of the gadget from the previous tutorial to do just that. We will go through three versions of this program with increasing complexity, although all three programs at first sight look the same, they all use the same grid lay out shown below.

For the sake of definiteness, we will assume that there are three different possible random events. This is easily modifiable with more or less rows.

These programs are designed to be built somewhere out of sight and then called from the room or rooms that they are wanted by a Run Program contraption.

1: Simplest Version

In the first line place a Roll To Thought contraption. In the parameters set the minimum value to one, the maximum value to three (the number of possible random events), and choose a descriptive Thought name to assign the output number to. I use the name “whichevent”.

You probably won't want a random event to occur every time that your guest does anything at all in the room where this is being used. Just a one in ten or one in twenty chance. For the sake of definiteness, let's say one time in twenty. That's a five percent chance.

Next to your first contraption, put a second Roll To Thought contraption set to generate a random number between 1 and 100 and assign it to the Thought doeseventhappen. (You can of course choose a different name for the Thought, but remember, no capital letters, spaces, or funny symbols.) After this use a Thought Less Than contrivance set to check that the Thought doeseventhappen is less than 5 (the chance out of a hundred that you want this to happen). Set the control knob to “All Pass” - the two Roll To Thought contraptions will pass automatically as contraptions, so you need to check that the Thought Less Than contrivance passes as well.

Beneath this, use a "multiple command" style of program. In each of the first two rows put a Thought Less Than contrivance, set to check that the thought whichevent is less than two and three respectively. Set the flow control knobs to Any Fail, and then in each escape hatch put a Show Page contraption to show each event's flavour text.

Note that in the example shown below, the final event has replaced the Show Page with a Run Program. Doing this allows you to have random events which are more substantial than just a little flavour text. For example if you have some sort of money system in your place then you might want to have an event where your guest is robbed and loses some random amount, or it could point to a program which has a Show Page contraption to show some flavour text about how an NPC has walked in and started talking to you together with some Add Page Access contraptions pointing to the initial fragments of an interactive conversation. The possibilities include anything that you can program.

Note that the escape hatch for the second event (the third row of the program) will only be reached if whichevent is equal to two. Any greater, and the Thought Less Than contrivance will fail and the program will continue to the next row. If on the other hand whichevent is only one, then the program will have already been diverted to the escape hatch in the previous row and will never reach this row at all. Why is this an improvement over simply using Thought Equal contrivances as in the previous program? That will be explained in the next version of this program.

 Thoughts can be variable parameters!

2: Some events are more likely than others.

You may want to have some events more or less likely than others. This is where the use of Thought Less Than as opposed to Thought Equal To contrivances comes in. What you can do is have an event correspond to a range of values for your whichevent Thought.

In the above example you could have the first event happen on a roll of one to three, the second event on a roll of four to eight, and the last event happen on a roll of nine. To program this, set the first Roll To Thought maximum value parameter accordingly, (in this case 9) and then set the Thought Less Than contrivances as appropriate - in this case the first should check to see if whichevent is less than 4 and the second to check to see if whichevent is less than 9.

3: Random events can happen with varying probability.

So you've built a nice fancy random event gadget. Very nice. But you want it to be a bit more flexible. When your guest is enjoying themselves rolling dice with jokers, you want there to be a high chance of a random event occurring. When they're in the woodshed however, you want a rather lower (but still non-zero) chance of a random event. You want to build your Random Event gadget with a parameter, a way of saying what probability you want to have of a random event occurring. Well you can.

We use the same program as above, with one change. In the above program, the Thought Smaller Than contrivance in the first line checks to see if the Thought doeseventhappen is less than five - this gave a five percent chance of a random event occurring whenever the program is called. This time go through the parameters for the Thought Less Than Contrivance and when it asks you whether you want to compare to Number, Thought or Memory, choose Thought. Finally, choose a name for a new Thought. We will choose chanceofrandomevent.

So just what is this Thought, chanceofrandomevent? Well that's the clever part. You don't define that in this program at all. You define it on the page where you call the Random Event gadget. So in your Playing Dice With Jokers room, you have a program with a Set Thought Contraption, that sets chanceofrandomevent to twenty, and then a Run Program Contraption giving you a twenty percent chance of having a random event happen there. In the woodshed on the other hand, you set the Thought chanceofrandomevent to five and then call the Random Event gadget, giving you a five percent chance of having a random event happen there. In other rooms you can have different chances of random events as you see fit.

Note that if you ever use this Random Event gadget without setting chanceofrandomevent first, then it will behave as if it is zero, giving you a zero percent chance of having a random event.

Note for budding programmers

What we have built here is a gadget with parameters. You have one program that can be controlled so that it behaves differently in different situations. This is one significant use for Thoughts. In the next tutorial we will look at another.


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

gameplay/guides/places/advtutvi.txt · Last modified: 2023/11/22 00:04 by kuhsodas