Quote: * losl is listening to Alkaline Trio - Armageddo...
blade2k » articles & tutorials

jump to:
Tutorials » Game Creation » RPG Maker 2000

Switch/Variable/Fork Tutorial


Reading Article
Author: SSBMasta
Posted on 08/02/2004
print :: back to list

S

witch/Variable/Fork Tutorial- By SSBMasta




SSBMastas Switch/Variable/Fork Tutorial

It is designed to help the newbies who need some help.

Okay this is just a little something I whipped up since I had nothing better to do. Dont expect much from it, I warn you, since Im just explaining basic functions of them and a few examples of where they can be used.

First lets define switch, variable and fork.

Switch-a marker that can be 1 of 2 values commonly referred to as "true" or "false"

Variable-A more complicated form of a switch that holds numerical values from -99999 and 99999(the values may be different; Im trying to go this from memory).

Fork-A statement that checks to see if a certain condition is true (IF this is like this, THEN this will happen. Its one big if/then statement.)

Okay, now for the actual explanations.

SWITCHES

Switches, variables, and forks are all essential in rm2k. Switches are used to perform some very basic and simple operations, like opening a treasure chest, making people disappear after you talk to them, stopping autostart events from repeating over and over and over and over.In this section I will explain some common uses of switches and how it works.

-TREASURE CHESTS

Treasure chests are one of the most common uses of switches, while it is also one of the simplest. To make a treasure chest:

Create a new event and give it the treasure chest graphic and set it to push key.

In the event commands, make the events that you want to have occur when the chest is opened (i.e. the show message, the add item, sound effects, or anything else you want).

After your events, make a change switch command turning on a switch of your choice. Make sure it turns it on.

On the upper part of the event window, click make new page.

On the next page, make the graphic that of an open chest, and in the upper left click switch for the appearance conditions and in the dialog choose the switch you just made. If you want you can add a message saying that the chest is empty.

What this does:

This event says that when the key is pushed, a message is shown, an item is added, a sound effect may be played, and a switch is turned on. The appearance conditions you set on the second page are what find when the switch is turned on. When the switch is turned on control of the event is shifted to the second page where the empty chest graphic is displayed, and every time you come back to the chest it stays open.(NOTE: You will need to use a new switch for each treasure chest!)

MAKING PEOPLE/THINGS DISAPPEAR WHEN THEY ARE TALKED TO

The concept of this one is very similar to that of the treasure chest. You have your commands on one page, move to another page that has a blank graphic, and youre good to go. To make things disappear:

1. Make a new event with the graphic of whatever will be there before the big disappearing act.

2. In this event make whatever commands you want to occur before the change takes place.

3. At the end of the commands make a command turning on a new switch.

4. Make a new page and click the switch box in the appearance conditions group and choose your switch.

5. Set the graphic on this page to a blank, or if you wish to make it transform set it to anything you want.

What this does: This event says that after any commands you need are executed, a switch will go on transferring the control of the event to the next page. The blank graphic will show that whatever there was will no longer be (or what it now is if you made a transformation).

STOPPING AUTOSTART EVENTS:

Autostart events simply wont stop until you do something to stop them. Using a switch is the most commonly used way to do it. The concept with this is exactly the same the first two. Since its the same Im just going to give a brief explanation of what to do.

Follow the steps for the disappearing event, but on the first page, set it to autostart (make sure the second page is BLANK, meaning everything blank except for the appearance conditions toggler). Doing this will cause your event to ensue, and then switching over to a blank page, and when the blank page is read you will be able to resume play as you wish.

In conclusion, switches are the main operator for performing small operations. While not very time consuming or complex, they are EXTREMELY important.

VARIABLES

Variables are just like switches, but instead of using true or false, it can be a huge variety of things. Say you wanted to keep track of Alexs money. This would be done by adding or subtracting from a money variable. Another big thing about variables is the ability to perform mathematics on certain values. Another use is if you want to make a cbs, and Joe needs something to keep track of his hp and mp. Variables are the key to the more complex situations in programming.

VARIABLE WINDOW

When you make a variable, you may be confused by what you see. We will go over it step by step.

One-This allows you to select a single variable to be changed.

Range-The range allows you to pick two numbers. The lower number is the smaller variable number, and the higher is the highest variable you wish to change. What this does is it selects all the variables that have a number in the range you selected to be changed.

Variable-This allows you to select a variable according to the value of a different variable (e.g. if variable 1 is set to 43, and you select variable 1 in the box, then variable number 43 will be open for change)

Set-Doing this allows you to immediately set the variable to any number without performing any operations to it.

+-The addition sign allows you to add a numerical value to your variable.

-The subtraction sign lets you subtract a value from your variable.

*- The multiplication sign lets you multiply the variable by a number.

/-The division sign lets you divide the variable by a number

Mod-The modulus command divides the variable by a number, but instead of taking the total it takes the remainder of the equation.

Variable (1)-This allows you to set your variable to the value of a different variable.

Variable (2)-This lets you take the value of a variable, then takes that variables value and uses it to find the number of yet another variable(it may be confusing but you should be able to get it)

Rand-This lets you set the variable to a number randomly chosen between the two numbers you pick.

Item-This sets the variable to the number of owned or equipped items that you choose.

Hero-This sets the variable to a certain stat of the hero

Event-This sets the variable to a certain stat of an event.

Other-This will set the variable to one of the pre done variables in the box of your choosing.

DISPLAYING THE VARIABLE IN A SHOW MESSAGE

You may want to display a variable in a message, like if a guy wants you to bring him 10 items, and each time you talk to him he tells you how many more you need. To display a variable:

Type this into the show message box: V[XXXX] with Xs being the variable number.

EXAMPLES OF VARIABLES IN USE

I now will show you some simple uses of variables. Much of the use of variables will require using forks, so I will now only explain the rest of it when we get to forks.

FIND 10 ITEMS

This is a simple procedure to make a thing that keeps track of how many items you have gotten for a certain quest or whatever. Note that you can change the 10 to any number you wish to use.

For this to work in the way intended, make about 10 events on a map, and give them all a graphic of your choice.

In each item event make some sort of message or whatever you want to have appeared when you get an item.

At the end of the coding on the first page, make a switch turned on, and make a new variable. Name it whatever you want, click the + sign, and set the value to 1.

Make a new page and have the appearance conditions that the switch you made is on, and set the graphic to a blank. The rest of this will involve forks so well wait until we get to that part.

What this does:

This basically has 10 events, each with a graphic of something. When you check these events, 1 is added to a variable, a switch is turned on, and the even disappears.

KEEPING TRACK OF THE HEROS X/Y COORDINATES

This really comes in handy for an abs, so if thats your goal pay attention to this.

Go to the database and open the common events tab.

Make a new common event and call it something like "xy coords". Set the type to parallel process.

In the commands area make a change variable command. Make 2 new variables; one for x coordinates and one for y coordinates. Choose one of these for this change variable command.

Click Set, and click the button for event.

In the event group, select hero in the first box, and in the second box select either x or y, depending on which variable you selected.

Make another event identical to the one you just made except alternate between the x/y variable.

What this does:

This event constantly sets two different variables to your heros x and y coordinates.

Im sure you can make several different uses of variables of yourself. These are just a few examples of using the different commands. Using forks will make variables much more powerful, which bring us to

FORK CONDITIONS

Forks check to see if a condition is true, and if it is true, then it will do something according to the result. Forks are also an extremely important part of RPG making, and should be used carefully. First lets get to know the fork working area.

Switch-This checks to see if a switch is on or off

Variable-This checks to see if a variable is set to a certain value, or if it is the same as, above, below, bigger or smaller, or "others" compared to your variable.

Timer-This checks to see if your timers current time is above or below the time mentioned in the fork.

Money-This checks if your current money is above or below the set amount.

Item-This checks if you have or dont have a certain item.

Hero-This lets you check if a her is in your party, is at a certain level, or is a number of other things.

Event-This checks to see if an event is facing a certain direction.

Vehicle-This checks to see if youre riding a certain vehicle.

Started by Decision Key-This checks to see if the event was started by a push key or not.

Play BGM Once-This checks to see if the background music has played through once or not.

Add ELSE Case-Checking this adds an extra case for if the checked condition is not true.

USES OF FORKS

Well continue the first variable tutorial now. See the first variable tutorial and continue from the end of that.

The next step is to make a new event on the map. (NOTE: If the items are all on different maps you need to make this a common event. An alternative to making this event is adding the fork right into the events. If you wish to does that skip this step.) Set this event to a parallel process.

Add a fork condition to the event checking to see if your variable is equal to 10 (If youre adding it to each event individually, make the fork before the change switch command). Do this by choosing your variable in the box, clicking set, and putting 10 in the field with 0 in it. Turn add ELSE case off.

In between the beginning and end clause of the fork, make whatever you would like to happen, like showing a message, turning on a switch, or whatever. You also should make a switch and add another page so that the parallel process wont keep repeating, and you can also change the dialogue to better suit the conditions. After that is done, you will be able to tinker with it a bit and get the results to your liking.

What this does:

This ends the event by either adding a fork to the end of each event or in a parallel process. If its in the event, it adds the variable, and then it checks to see if the condition is true. In the parallel process, the fork checks to see if the event is true, then activates a switch ending the parallel process and changing the event to suit the conditions better.

MAKING A FUNCTION WHEN A TIMER REACHES 0

This simply checks to see if the timer is 0, and if so It will do something.

Make an event and make it a parallel process.

Create a timer and change the specs to your liking and start it.

Make a fork condition.

In the fork dialogue, click timer. Set it to 0 seconds and minutes and select below from the drop down menu.

Deselect the add ELSE case checkbox.

In the fork make whatever commands you want. If youre using a timer in a day night system, you can change some switches or change screen tones, or you can make a message of failure and blow up the world, its your