This tutorial is designed to show you the different things you can do with random variables. More specifically, this tutorial will show you how to create random chest items, random conversation and random battles.
Prior Knowledge Required
- Creating a new event
- Working with conditional branches
- Creating a working chest
- Creating enemies and troops
A variable is something that stores a number.
1. Open up your event commands and select control variables. It's the second one in the right-hand column of the first page.
2. Click on the drop down box next to Single at the top. This will open up a new window showing all of your current variables.
3. Leave the Set option marked under Operation.
4. Select an empty slot (should be blank) and type in a name in the bottom box next to Name: You should use a meaningful name. I have named mine Random. The best part is that you can use the same variable for all your random variable needs.
5. Now look under the options listed under Operand. Click on the circle next to Random. Doing this will show you two boxes, each currently filled with 0. This function allows you to determine how many items to choose from.
For example, if you select 0-3, the variable will select the commands associated with 0, 1, 2, or 3 at random. So really, 0-3 gives you four options because it counts the 0!
http://i145.photobucket.com/albums/r228 ... es/1-3.png[/IMG]
2. Click on the drop down box next to Single at the top. This will open up a new window showing all of your current variables.
3. Leave the Set option marked under Operation.
4. Select an empty slot (should be blank) and type in a name in the bottom box next to Name: You should use a meaningful name. I have named mine Random. The best part is that you can use the same variable for all your random variable needs.
5. Now look under the options listed under Operand. Click on the circle next to Random. Doing this will show you two boxes, each currently filled with 0. This function allows you to determine how many items to choose from.
For example, if you select 0-3, the variable will select the commands associated with 0, 1, 2, or 3 at random. So really, 0-3 gives you four options because it counts the 0!
http://i145.photobucket.com/albums/r228 ... es/1-3.png[/IMG]
1. Create a chest event. After the turn left, turn right, turn up commands, click on Control Variables.
2. Select the random variable you had created previously.
3. Now it's time to decide how many items you would like your chest to choose from. Remember, 0-5 would give you 6 items, not 5. I want my chest event to choose from 4 items to give. So, I need to set the random operand to 0-3.
4. Next, you need to create a conditional branch for every possible item your chest can give. Since I had selected 0-3, I will have to create 4 conditional branches. Please note, if you do not create a conditional branch for one of the random operands, no commands will run since there aren't any.
2. Select the random variable you had created previously.
3. Now it's time to decide how many items you would like your chest to choose from. Remember, 0-5 would give you 6 items, not 5. I want my chest event to choose from 4 items to give. So, I need to set the random operand to 0-3.
4. Next, you need to create a conditional branch for every possible item your chest can give. Since I had selected 0-3, I will have to create 4 conditional branches. Please note, if you do not create a conditional branch for one of the random operands, no commands will run since there aren't any.
- Okay, so first, I need to create a conditional branch for when the random variable equals 0. Go ahead and create an item to give.
- After you do that, create another conditional branch for when the random variable equals 1 under the else statement. Keep doing this until you have created items for all of your possible random variables.
http://i145.photobucket.com/albums/r228/yisuz/Random%20Variables/2-3.png[/IMG]
1. Create an npc event.
2. Click on control variables and select your random variable.
3. Decide how many different messages you want your npc to choose from and set the random operand accordingly. I want my npc to choose from 6 different things to say, so I've set my random operand to 0-5.
4. Create 6 different conditional branches each with different text messages.
2. Click on control variables and select your random variable.
3. Decide how many different messages you want your npc to choose from and set the random operand accordingly. I want my npc to choose from 6 different things to say, so I've set my random operand to 0-5.
4. Create 6 different conditional branches each with different text messages.
http://i145.photobucket.com/albums/r228/yisuz/Random%20Variables/3-3.png[/IMG]
This is intended to be used with games in which the enemies are visible.
1. First, you need to have already created different enemies and troops. I have used the goblin enemy and have created 5 different troops for the goblin.
2. Click on control variables and select your random variable.
3. Decide how many troops you want your program to choose from and set the random operand accordingly. I want my program to choose from 5 different troops so I've set my random operand to 0-4.
4. Create 5 different conditional branches each with different battle processing commands for the different troops.
1. First, you need to have already created different enemies and troops. I have used the goblin enemy and have created 5 different troops for the goblin.
2. Click on control variables and select your random variable.
3. Decide how many troops you want your program to choose from and set the random operand accordingly. I want my program to choose from 5 different troops so I've set my random operand to 0-4.
4. Create 5 different conditional branches each with different battle processing commands for the different troops.
http://i145.photobucket.com/albums/r228/yisuz/Random%20Variables/4-3.png[/IMG]
And now, a DEMO.
I hope this tutorial has showed you some of the different things you can do with random variables. If you have another use for the random variable and would like for me to add it to this tutorial, please post a detailed reply. Thanks and enjoy.