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

8,176 visits, 17,230 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.

Now, let’s look at an in-game use for probability tables. The advanced example project demonstrates two similar methods for using these tables: random encounters on different terrains, and with interactable ‘item boxes’. The project is all done with placeholder art, so just use your imaginations!

There are two types of terrain square – grass and cave. Handily, they have their own probability tables. So the first thing to do is put those two terrain objects into a family (in the example it’s called EncounterZones) and give them a family instance variable called EncounterID. This variable will be used to tell the game which table it should be drawing values from when the player collides with a zone.

Condition

Player ▶︎ On collision with EncounterZones

Action

AdvancedRandom ▶︎ Set current probability table to EncounterZones.EncounterID

Now, every time the player walks on one of these terrain tiles, the correct probability table will be set. The debug box in the example project uses the AdvancedRandom.Weighted expression to display the value pulled from the table when the player walks on a tile too.

The item boxes work in a similar way, but the player has to press a button to pick an item and set the correct table. The ItemBox object has a similar instance variable to the EncounterZones family – ItemSetID. This is needed because each ItemBox in this project works with a different probability table.

Condition

Keyboard ▶︎ On Z key pressed

Sub-event Condition

Player ▶︎ Is overlapping ItemBox at offset (8,0)

OR

Player ▶︎ Is overlapping ItemBox at offset (-8,0)

OR

Player ▶︎ Is overlapping ItemBox at offset (0,8)

OR

Player ▶︎ Is overlapping ItemBox at offset (0,-8)

Sub-event Action

AdvancedRandom ▶︎ Set current probability table to ItemBox.ItemSetID

Now, when the player walks up to an item box and presses the Z key, the probability table will be set and you can trigger whatever action(s) you like.

And it’s as easy as that. It’s quite simple to set up probability tables and they’re really quite versatile when you know how to manipulate them. These projects showed relatively basic ways of implementing these tables, but I hope you can see how you could easily build up more complex systems with them!

  • 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.