# How to use Random Variables

<< All Articles | Print

Introduction

Learn and master the basics and advanced concepts of random variables, including defining and using restrictions within the editor. To use random variables, you need to ensure that the "Advanced" option is selected for variable options within the game properties page.

Step One: Understanding Diceâ€‹

The very first thing you need to know when working with random variables is that you need to understand the "Dice" concept. The "Dice" concept is simple, 1D2 can be used as an example of defining a random variable. The "1" in 1D2 represents how many dice are thrown. The "2" in 1D2 represents how many sides there are on the dice. This means 1 dice of 2 sides on each dice. This means a number generated can be 1 or 2. 1D6 would represent the throw of one standard six-sided dice.

Another example, please note this explanation can be complicated but if understood, can provide an easier way of understanding multiple dice: 3D100: this means there are three dice of 100 sides each. A number can be generated anywhere from 3 to 300. To make it more simple when using the multiple dice, think of how it would generate a number if there were 1 die. 1D100 it would mean the number is from 1 - 100, the lowest is 1 and the highest is 100. Do that two more times since there are three dice to get three sets of 1-100, 1-100, 1-100. Add the each side up, 1+1+1 = 3, 100+100+100 = 300, the least amount in 3D100 is 3, the greatest amount is 300.

Step Two: Defining a Random Variableâ€‹

At this point, you know the first half of defining a random variable. The second half deals with how it is defined. You define random variables in the variable enhancements menu which can be found by clicking the Variables button next to a link, which looks like a cross with a line under it. The menu gives a list of variables, a drop down menu, and a text input box. You cannot just type 1D100 in the input box, you need to define a function for how the variable is defined. This is where the drop down menu comes into play. You have: addition, subtraction, multiplication, division and many others.

If you just want a random number from 1-100 (1D100), use the "reset" function. This will be the highest used function in random variables. If you already have a number defined in a variable, use the add/subtract/multiply/divide function. These 4 functions are self-explanatory.

Sâ€‹tep Three: Using Random Variables

At this point you know everything on defining random variables. But now you need to know how to use them properly in a game. Random variables do not need to be just used in small parts of games where there is a card game, they can be used to help the author carry the game along. For example, a player could be progressing well and a SKILL variable records that, then he must scale a tall cliff, using a random variable you can manipulate how successful the player is in conjunction with the SKILL variable. So if his SKILL variable is low, the chances of success are slim whereas if his SKILL variable is high, the chances of success are high.

To do the above technique, you need to have a firm knowledge of the advanced editor. With that in mind, i will start with doing an example and I hope you try this when you are in the adv editor. We will create a random event that will take us to one of two pages. Create a page and label it, "Defining the random number." On that page, open the variable enhancements menu and set a variable as "reset" and input "1D2". Link this page to another page and label that page, "Event!" On this page create two linked pages, "Event 1" on the first page and, "Event 2" on the second page. Open the restrictions menu for "Event 1" and for the random variable, put a min. restriction of 1, and max. restriction of 1. This means that for the link to be active, the random variable must be 1.

Open the restrictions menu for "Event 2" and for the random variable, put a min. restriction of 2 and leave the max. restriction blank. This is because the only numbers that are possible are 1 and 2, if it were more than two, you would need to set a maximum restriction of 2. Test your 'game' out and see how the random variable manipulates what page you go to. If you would like to see what number was generated, use the "%%" symbols to show the variable on the page. If your variable was named "randvar" then to show it on the page, type "%%RANDVAR%%" making sure you use capital letters.

As you can see, random variables are not very hard to grasp and can be used to make a good game, great.