Getting to grips with Advanced Random's Probability Tables

25

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

basic-probability-table.c3p

Download now 157.44 KB
.c3p

advanced-probability-table.c3p

Download now 167.17 KB

Stats

7,990 visits, 16,963 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Oct, 2019.

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.

  • 5 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Probability tables are a great feature.

    Before the advanced random plugin you would probably have done something like choose( "A", "B", "B", "C", "C", "C", "C" ) for the 1xA, 2xB and 4xC example. Now imagine doing that for 10xA, 20xB and 40xC :P

    Great tutorial more people need to know about this feature.

  • Thanx.. I am just finishing a project that this would have saved a ton of extra coding.. My next project I will try this out and create a template for the furure.. Thanx again

  • Great! Didn't know this was possible. It's exactly what I need for loot drops. 👍

  • The only part i dont understand is the "load from JSON string" action where you have the "input" string parameter. what's the purpose of this?

  • Thank you so much! It clears a lot.