Ok, I wrote a tutorial on Variable Splitting, but didn't realize that there are some people that may not fully understand Variables, so that is what this tutorial is for.
INDEX• What Variables Are
• Basics of Variables
• Using First Variable in Event
• Creating Currency
What Variables Are:Variables are objects that hold a numerical value. Pretty much, variables are needed for any game to be considered a good game. Variables are controlled by Fork Conditions, which I will also explain in this tutorial.
Basics of Variables:The Variable Operation command is in the left column of the first tab. To demonstrate how variables can be used, I will create a series of events (including a bank later on) for you to practice with.
First let’s go over the layout of Variable Options command.
Using Our First Variable for an Event:Ok we are going to create a variable then use it for a small event.
Create a new event set on Push Key and select a sprite for it. I chose a dog. Now create a message saying: “Find me 3 cats and I will give you 100 GP!”
Ok, I bet you’re wondering, “How will he know when I have three cats?” That’s where our friend, the variable, comes in play.
Apply the Event then hit OK.
Create a new event set on Push Key on the same map and set its graphic to a cat. In the Event Commands go to the Variable Operations.
In our Variable Operations menu, Press the […] button,
Then change the name of Variable 1 to “Cats”. This is the name we will use for this entire event.
Right now, our Variable has a default value of 0. When we pick up this cat, we want our Value of “Cats” to increase by 1, since we found 1 cat.
Set Operation to “Add” then in Operand, select “Number” and type “1” in the blank, like so:
Hit OK. Now, every time we click on this cat our variable will add one. Now we need to turn the cat off that way we cannot exceed 3 cats. Remember, the Dog said 3 cats, not 2, nor 4, nor 20. He wants three, so three is all we need.
You can either close off this event by a switch, and make three separate cat events, or you can use this same one three times in a row and use the “Cats” variable to close it off. Since this is a variable tutorial, we will use the variable way! Let’s pretend this is a bundle of Cats and we are picking all three up.
We have already set our Variable increase command, we just need to turn it off. Create a new page and set the graphic to blank. Above the graphic where it says “Precondition” check the Variable and select Cats from the list. In the drop down box select “Equal to” and then put 3 in the number field. This says when Cats is equal to three, this event is triggered, causing our little friend to vanish disallowing us to continue collecting cats.
Ok, now we go back to the Dog event. Create a new message that says:
“You have \v[0001] cats”
\v[] is the command used to display a variables amount. Just place the variables number in the brackets.
You can test this out if you wish. Ok, now we have to make the Dog check how many cats we have so he will know if we have three.
Double click in Event Command of the Dog, and go to the 3rd tab. In the right column there is an event either labeled “Fork Condition” or “Conditional Branch”. Choose this. Select the Variable option, and then pull out “Cats” from the list on the right (it should be there by default). Next to “Number”, put 3 and leave where it says Equal To. Also, leave the Execute Handler if Condition Not Met. That just says “If ‘Cats’ is not equal to 3, then these are the events that will happen instead”. Here is example incase I lost you lol:
Ok, here is what our Event Commands should look like so far for Dog:
Now, right under where it says “Branch if Var [0001 Cats] is 3” set an increase gold held event, and give your party 100 GP. Then create a message saying “You got me three cats. Thanks”. After that create a switch to turn the dog off, otherwise he will continue to give you 100 GP, and we don’t want that to happen!
Under the Else Handler, create a message that says “You only have \v[0001] cats”. That takes care of what he says if you have not met his requirements.
Creating Currencies with Variables:Now we will create our own currency using Variables!
Create a new event and give it a sprite. Make it Push Key. In the Event Command, go to Variable Operation. Open the list and click on the second spot. Name it Coins then hit ok. In the Operand, select Add, then in the number type 1. Hit Ok, and then create a message that says “You just received 1 coin. You now have \v[0002] coins.”
Ok, now create a new event with a sprite. Create a message and have him say “I will give you this item for 5 Coins”. (We will use some random RTP item for this.)
Now create a show choice event located in the first tab, left column. Hit ok. Under “Yes” create a Fork Condition, select variable, pick the Coins variable from the list, then type 5 in the blank, then select “Greater Than or Equal To”. Leave the Handler checked at the bottom. This basically says if we have 5 or more coins than we can buy his item.
Ok, under where it says “Branch if Var [0002 Coins] is 5 or more” create a message that says “You have \v[0002] coins. Do you want my item?”
Create another show choice, and under that “Yes” add any item you wish to, then go to the Variable Operations command. Now select our Coins variable from the list. In the Operand select “Subtract” and leave the value at 5. He just took our 5 coins needed to buy the item! Under both the No options, make a message that says “Ok, maybe another time.”
Now at the bottom of these events where it says “Else Handler”, or something to that effect, create a message “You only have \v[0002] coins! This isn’t enough!” This I is his rejection statement if we don’t have enough. Your coding should look like this:
Ok so now we have created our own currency, as rushed and plain as it may seem. For now I am going to put this on hold and will come back with more information in a couple days. I will quickly summarize what other features Variables can do:
- You can set your X coordinate and Y coordinates to variables, which helps in puzzles.
- You can set the amount of a certain item held to a variable, for quests or something.
- You can set any hero stat to variable, for custom battle systems, or more.
- You can set your gold held to variables.
- You can create random values into variables, for mini games (dice, blackjack, ect...)
- You can create a bank using variables.
I will go over each of these in full by the time this tutorial is complete. Enjoy what I have so far!