Brick's Much Needed Switch, Variable, and Fork FAQ -------------------------------------------------- DISCLAIMER ---------- This FAQ was written because switches, variables, and forks seem to give people more trouble than any other aspect of RM2k. Only two websites on the entirety of the internet have my permission to post this FAQ; my own (brickroad.simplenet.com) and Don Miguel's (rpgmaker.chat.ru). If you downloaded this FAQ from a site other than those two, please email me at brikroad@tampabay.rr.com and let me know. Thanks. WHAT ARE SWITCHES? ------------------ Switches are boolean memory locations. That means that a switch can only have one of two values: 0 and 1. A switch with a value of 0 is "off." A switch with a value of 1 is "on." All switches, when you first begin to create an RPG, are turned off. Switches affect your RPG by using switch conditionals in the event editor. WHAT ARE SWITCH CONDITIONALS? ----------------------------- Go into RM2k an create a new event. You will see a long list of conditionals down the upper-left side of the editor. Two of those conditionals can be set to switches. If the checkbox next to one of those conditionals is checked, then the event will only take place if the corrosponding switch is turned on. HOW DO I USE SWITCHES? ---------------------- In the event editor is a command that reads "Change Switch." Clicking it brings up a box with several options, which I will detail below: Create Switch: This tells the event which switch to change. There are three different options. "One" lets you set any switch you like; click the pulldown menu to get a list of all the switches in your game (both used and unused) and chose one to change. You can also name your switches, for easier reference. "Rang" lets you change more than one switch at a time. There are two numbers; the number in the left box must be less than the number in the right box. Every switch in between the two numbers will be changed. For example, by choosing "5" in the left box and "9" in the right box, all of the switches numbered 5 through 9 will be changed. "Varia" changes a switch based on a variable. RM2k will read the variable you choose, then change the switch whose number matches that variable. Read below for more details on variables. Operation: This describes how the switch will be changed. "On" means that the switch will be turned on. "Off" means that the switch will be turned off. "On/Off" means that the switch will toggle itself. That is, if the switch is on, it will turn off. If it is off, it will turn on. HOW MANY SWITCHES DO I GET? --------------------------- RM2k starts by allocating 100 switches for you. But, by going into the "Change Switch" section of your event editor, and clicking the pulldown box under the "Create Switch" option, you can allocate yourself more. Once in your list of switches, push the "Max Field Number" button. This will allow you to allocate yourself up to 5000 switches, which is more than enough. As a general rule, a finished game should only allocate itself as many switches as it needs. So if you're ready to release your demo, and you've only used 53 switches, set your max field number to 53. Every little bit helps in keeping your game's filesize small, after all. WHAT USES DO SWITCHES HAVE? -------------------------- Since switches can only be set to one of two values, any event that has two functions can benefit from a switch. Such things include and NPC which says something different the second time you talk to him, a treasure box, or a cutscene that only runs once. Below is a detailed example of a fairly simple switch-related event, a treasure box. Create a new event. Choose the treasure box graphic and make sure all of the conditional boxes are unchecked. Set the start condition to "Push Key" and the priority type to "Common Char Above." In the events box, include a message saying which item the player has received, a command to award the player that item, then finally a change switch command to turn a switch on. Name this switch "Treasure Box" or some other descriptive title, so you can remember its name later on should you need to refer to it. Now click the "New Page" button near the top of the event editor screen to create a second event page. This time, choose the open treasure box graphic and set the conditional to "Switch 'Treasure Box' On." Include a message saying that the box is empty, or something along those lines. Now, you will only be able to receive that particular item once so long as that particular switch remains on. WHAT ARE VARIABLES? ------------------- Like switches, variables are memory locations. Unlike switches, they can hold just about any value, positive or negative. So whereas a switch can only be on or off, a variable can be on, off, or anywhere in between. RM2k starts out with all variables being equal to 0. Variables affect your RPG by using variable conditionals in the event editor. WHAT ARE VARIABLE CONDITIONALS? ------------------------------- In the event editor, along the top-left side of the screen, are a series of checkboxes, one of which is marked "variable." When this checkbox is marked, the event will only work if the specified variable is greater than or equal to the specified number. Also, the "Fork" command has a field which is en even more powerful variable conditional. Forks are explained below variables. HOW DO I USE VARIABLES? ----------------------- In the event editor is a command called "Change Variable." Click this to get a wide variety of options on how to manipulate certain variables. They are: Create Variable: This tells the editor which variable you want to manipulate. "One" allows you to choose any variable you have created by showing you a list of all your variables. "Rang" allows you to input two numbers; the number on the left must be smaller than the number on the right. This will change every variable in between those numbers. If the left number was 5 and the right number was 10, then all variables 5 through 10 would be affected. "Varia" allows you to choose a variable from your list. RM2k will read that variables value, and the event will affect the variable whose number matches that value. Operation: This tells you how the variable is to be affected. "Set" sets the variable to the "Operand," no questions asked. The next four symbols are your basic arithmatic functions; + for addition, - for subtraction, * for multiplication, and / for division. (When dividing variables, the remainder is dropped.) As of yet, I have no clue what "Surpl" does. I've played around with it and still haven't found its use. As soon as I do, I'll put it here. Operand: This determines the second number to modify your variable with. "Set" is equal to whatever number you type into the box, no questions asked. The first "Variab" will take any other variable to use as an operand. The second "Variab" takes the variable in the corrosponding location for use as the operand. "Rand" will randomly determine a number in between the values of the left and right boxes. For example, if the left box is 5 and the right box is 9, a random number between 5 and 9 will be chosen. "Items" has two options: "Owning Number" (which finds the number of the chosen item owned by the player, and sets that to the operand) and "Equipment Number" (which finds the corrosponding number in your item/equipment list in the database, and sets that to the operand). "Hero" allows you to set the operand to virtually any status field of any of your heros (Level, Experience, Current HP, Current MP, Max HP, Max MP, Attack Power, Defense Power, Mind Force, Agility, or the equipment number of anything that character is equipped with). "Character" allows you to choose any event on the current map, and set the operand to a variety of values corrosponding to that event (such as the Map ID, X coordinate, Y coordinate, etc). "Other" rounds out the options by allowing you to set the operand to the current amount of money held, the amount of time left on the clock, the party size, number of saves, number of battles, number of victories, number of defeats, number of escapes, and the current midi tick (which, to spare myself the explaination of how RM2k reads midi files, is another way of finding a virtually random number). CAN YOU REPEAT THAT IN ENGLISH? ------------------------------- Think back to your algebra class. Remember when your teacher was explaining equations? In algebraic terms, a variable is a number that you don't know, and is represented by a letter. Here is a simple algebraic equation: x + y = z Basically, what you do with the "Change Variable" command is tell RM2k how to build your equation. First, you tell it the beginning value with the "Create Variable" field in the "Change Variable" menu. Think of that as the 'x' in the equation above. Then, you tell it what kind of operation to do with the "Operation" field. Finally, you tell it the manipulation value, or the 'y' in the equation above. 'z' is the final product of the equation, and is what your variable has been changed to. Let's say I wanted to set up the equation 2 * 3 = 6 in RM2k. I'll name my variable "Equation." Remember, to begin with all variables are equal to zero. So the first thing I want to do is initialize my variable to 2. Here's how you would fill out the three fields in the "Change Variable" menu: "Create Variable" : "One" (And I'll name it "Equation.") "Operation" : "Set" (Because I want to set the variable to the number 2.) "Operand" : "Set" 2 (Because 2 is the value I want the variable to be.) Now the variable "Equation" is equal to 2. Next, I want to create the equation above. In order to do that, I would use the following fields in the "Change Variable" menu: "Create Variable" : "One" Equation (Because "Equation" is the variable I want to change.) "Operation" : "*" (Because it is a multiplication equation.) "Operand" : "Set" 3 (Because 3 is the number I want to multiply by.) THAT'S ALL KIND OF CONFUSING. CAN'T I MAKE A GAME WITHOUT VARIABLES? --------------------------------------------------------------------- Most definately. In fact, RM2k's predecessor, RPGMaker 95, didn't even have variables. You can build a perfectly decent game just using switches. It is beneficial, however, to learn how to use variables. They are very, very powerful. Virtually any numeric value imaginable in your game can be set to a variable and played with, and variables are the heart and soul of good mini games (even simple block puzzles), graphic tricks (like a world map function), and even custom spells (like a Steal ability). If you're sketchy on variables at first, and this FAQ isn't helping, just forget about them. WHAT USES DO VARIABLES HAVE? ---------------------------- Since variables can hold virtually any value of any numeric field in your game, their uses are endless. Variables can be used to do anything from regulating damage in lava fields, to making random teleporters, to making a world map, to keeping track of custom numeric fields, and the list goes on and on and on. Here are two very simple (and wildly different) uses of variables. The first is a simple variable event. Let's say you want to have a book that cannot be opened unless a character named Bob has at least 100 MP. Create a new variable named "Bob's MP," and set it to Bob's current MP score. Here's how the three fields would look: "Create Variable" : "One" Bob's MP "Operation" : "Set" "Operand" : "Hero, Bob, MP" Now, whatever Bob's current MP score is, it's now set to the variable named "Bob's MP." Now create your book event with the conditional "Variable, 100." If Bob's MP isn't at least 100 when he touches the book, the event will not take place. The second example I'll use is a custom numeric field. Say your game has a special kind of shop which does not accept regular money. This shop only accepts hard to find Magic Coins. In this case, create a new variable called "Magic Coins." Every single event in which your character gains or loses these Magic Coins, just use an event to alter the variable accordingly. So, if the hero finds 10 Magic Coins in a box, your three fields would be: "Create Variable" : "One" Magic Coins "Operation" : "+" "Operand" : "Set" 10 Now that he's got ten coins, your hero wants to buy a powerful item from the special shop which costs 7 Magic Coins. The three fields would be: "Create Variable" : "One" Magic Coins "Operation" : "-" "Operand" : "Set" 7 Those two examples are some of the bare bones simplest things you can do with variables. With their help, there is very little in RM2k that cannot be done. WHAT ARE FORKS? --------------- Forks, in conjunction with variables, are exteremely powerful commands. If you have programming knowledge in any language known to man, think of a fork as a simple "If...Then...Else" statement. If you don't, think of forks as just that - a fork. Using a fork in an event is just like you're making another conditional in that event (read about conditionals in the sections above). HOW DO I USE FORKS? ------------------- Select "Fork Conditions" from the third page of your event menu, but leave the bottom checkbox unchecked, and press OK. You'll notice that instead of adding one line (like most event commands), you have added three. And they look something like this: Fork [conditional] <> End Case Any commands you add in between the "Fork" and "End Case" will only happen if the fork's conditional is true. If the conditional is not true, then all the commands in the fork are ignored. In programming terms, it would be "If [conditional is true] Then [commands]." Had you checked the bottom checkbox in the "Fork Conditions" menu, it'd look something like this: Fork [conditional] <> Excepting Case <> End Case Any commands you put in between "Fork" and "Excepting Case" will only happen if the fork's conditional is true. Any commands you put in between "Excepting Case" and "End Case" will only happen if the fork's conditional is false. In programming terms, it would be "IF [conditional is true] Then [commands] Else [commands]." Obviously, checking the bottom option box makes things a little more complicated, but also more powerful. I'll show you what I mean below in my examples. WHAT ARE FORK CONDITIONALS? --------------------------- Fork conditionals are exactly like event conditionals, only there are more of them. There are two full pages of fork conditionals, located above the option checkbox. They are: "Switch" : Fork occurs if the chosen switch is on (or, if you choose, off). "Variable" : This is much, much more powerful than the normal variable conditional on the main event screen, basically because here you have the power of comparison. First, choose the variable you would like to compare. Then, select one of the two checkboxes (the top one compares the variable to a set number of your choice, the bottom compares the variable to another variable of your choice). Finally, choose your comparison type. "Same" means both the first and second number are equal. "Above" means the first value must be greater than the second. "Below" means the first value must be less than the second. "Bigger and Smaller" seem to be the same as "Above and Below," but I haven't experimented with them. And I'm not entirely sure what "Others" does. I'll include that information when I update this FAQ. "Timer" : This sets the conditional to the time left on the clock. Choose "Above" if you want the fork to take place if there is more time than what you've chosen, and "Below" if you want the fork to take place if there is less time. "Money" : This sets the conditional to the amount of money you have. Choose "Above" if you want the fork to take place if you currently have more money, or "Below" if you want the fork to take place if you have less. "Item" : Sets the conditional to any item you like. Choose "Has it" if you want the fork to take place if the party has said item, or "Doesn't have it" if you want the fork to take place if the party doesn't have it. "Character" : First, choose any event you like on the current map. Then choose a direction. The fork will only occure if the chosen event is facing the chosen direction. "Vehicle" : The fork only occurs if the party is riding in the chosen vehicle. The "Hero" conditional is more diverse than the rest. Click "Hero" to get another menu, this one chock full of different conditionals to use. First, decide which hero to use, then: "Is in Party" : Fork will only happen if the character is in the party. "Name" : Fork will only happen if the character's name is the same as the field. This is rather pointless, since the "Name Character" function is broken in RM2k. "Level" : Fork will only happen if the character's level is the same as the selected number, or above. "HP" : Fork will only happen if the character's HP is the same as the selected number, or above. "Special Skill" : Fork will only happen if the character has the selected skill. "Item" : Fork will only happen if the character is equipped with the selected item. "Condition" : Fork will only happen if the character is currently afflicted with the selected condition. I haven't experimented with the last two option, but I imagine "Play BGM Once" means the fork will only occur if the BGM has played through at least one time. WHAT CAN I PUT INSIDE OF A FORK? -------------------------------- Inside your fork, you can do whatever you like! Any event command is available for use in a fork, even another fork. If you wanted, you could nest a hundred forks inside of each other. This gives you complete control over every aspect of game conditionals. WHAT IS THE DIFFERENCE BETWEEN A FORK AND AN EVENT PAGE, THEN? -------------------------------------------------------------- Honestly, there is no difference. Anything you can do with a fork, you can also do with an event page. But, since a fork has more conditionals and the option of an excepting case, and since they can be integrated directly into your event code, they are a little easier to keep track of and a little more versitile. It's much easier to sketch out an event with 10 forks than it is to sketch an even with 10 pages, in other words. FORKS ARE ALMOST AS BAD AS VARIABLES! CAN I MAKE A GAME WITHOUT THEM? ---------------------------------------------------------------------- Again, it's no problem. Like I said earlier, you can make a perfectly good game relying just on switches and even conditionals. Forks, however, are nice to know for things like mini games and simple even differenciations. Also, some of the more powerful variable comparisons can only be done using forks. WHAT KINDS OF USES DO FORKS HAVE? --------------------------------- I'll give two simple examples of forks; the first which has no excepting case, and the second which does. The first example is a simple fork in the middle of a conversation. Let's say you're hero is talking to his friend about a monster they're about to fight. The friend mentions that the monster is weak to fire magic. If your hero has a fire magic spell, you want him to say something. It would look something like this: Message "Friend: The monster is weak to fire magic!" Fork [Hero, Special Skill, Fire] Message "Hero: No problem! I already have the Fire spell!" Message "Friend: Alright!" End Case Message "Hero: Let's go!" If the hero has not yet learned the Fire spell, the conversation would be: Friend: The monster is weak to fire magic! Hero: Let's go! But, if he does have the Fire spell, then the commands in the fork would change the conversation: Friend: The monster is weak to fire magic! Hero: No problem! I already have the Fire spell! Friend: Alright! Hero: Let's go! Now let's look at a fork with an excepting case. Let's say you have a switch called "Puzzle Complete," which is turned on after the hero completes a puzzle. You have a teleport tile which will take the hero to the next room if the switch is on, but will send him back to the last room if it isn't. It would look like this: Fork [Switch "Puzzle Complete" is on] Teleport (to the next room) Excepting Case Teleport (to the last room) End Case In this case, if the switch is indeed on the first command will initialize, sending the hero forward. If not, the second command will initialize, sending the hero back. WHERE CAN I FIND YOU IN CASE I HAVE QUESTIONS? ---------------------------------------------- If this FAQ didn't answer all your questions, I'm afraid I wouldn't be much more help. If you ask me (via e-mail, ICQ, or on IRC) about switches, variables, or forks I'm liable just to send you this text, or just repeat the things i've already said in it. If you're still confused about these topics, your best bet is just to jump into the editor and play around. Learn by trial and error. Try downloading other people's games and analyzing their events... look how they use their switches and variables to make their events do cool things. And that's the end of the FAQ. Hope it helped!