Basic setup of tables
It’s incredibly easy to create a probability table. You just add the Advanced Random plugin to your project and use the Create probability table action with some kind of trigger, like On start of layout. Bam! Table made. But there’s nothing in it, so it’s pretty much pointless.
Luckily, the AR plugin has actions for adding (and removing, but more on that later) entries in your probability tables. The way I’ve done it in the basic example project is as follows:
Condition
System ▶︎ On Start of Layout
Sub-event Action
AdvancedRandom ▶︎ Create probability table called “Animals”
AdvancedRandom ▶︎ Add entry “Cat” with weight 1
AdvancedRandom ▶︎ Add entry “Dog” with weight 1
AdvancedRandom ▶︎ Add entry “Lion” with weight 1
AdvancedRandom ▶︎ Add entry “Bear” with weight 1
AdvancedRandom ▶︎ Add entry “Fish” with weight 1
These events will create the table and populate it with weighted entries – in this case, all the weights are equal, so each item has the same probability of being pulled from the table. If you want to use more than one table, you can repeat these events in more sub-events to build new tables. For instance, in the example project, a second table utilising differing weights in its entries gets built.
If you’re only using one table, you don’t need to do any additional setup, but if you want to switch between tables, you’ll need to use the Set current probability table action from the AR plugin. As a side note, whichever is the most recently created table will be the one Construct uses told otherwise.
Going back to the basic example, certain keys are used to switch between the two probability tables. The events for this are:
Condition
Keyboard ▶︎ On “A” pressed
Action
AdvancedRandom ▶︎ Set current probability table to “Animals”
Condition
Keyboard ▶︎ On “F” pressed
Action
AdvancedRandom ▶︎ Set current probability table to “Food”
This is a simple example but shows how you can switch quite easily between probability tables depending on which you need to use.
Talking of using tables, that all depends on what you need them for, but at their simplest level, these tables can be used to pick random values in just one event. In the example project, when the spacebar is pressed, a value is picked and that value is displayed in a text object, called RandomOutput in this example:
Condition
Keyboard ▶︎ On “Spacebar” pressed
Action
RandomOutput ▶︎ Set text to AdvancedRandom.Weighted & newline
The above action will add text to anything already in the box, on a new line. So, you can create a list of random draws from the probability table, to give you an idea of how the weightings work.
And that about sums up what you can do with the basic example file. For some of the more complex mechanics, we’ll need to look at the advanced example file.