Home
Help
Search
Calendar
Login
Register
Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
New forum theme up and running!
Charas-Project
»
Game Creation
»
Requests
»
RPG Maker Programming
»
Switches: A Basic Guide
« previous
next »
Print
Pages: [
1
]
Author
Topic: Switches: A Basic Guide (Read 3673 times)
WarxePB
Action Sue
Royal
Posts: 3,601
What killed the dinosaurs?
Switches: A Basic Guide
«
on:
May 31, 2011, 03:11:54 AM »
Switches: A Basic Guide
Switches are a vital component of the RPG Maker experience. Without a basic knowledge of switches, you're probably not going to get far - which is where this guide comes in.
This guide is a basic overview of switches. I'll be covering their function and applications, along with three examples.
1. What is a switch?
Let's use an analogy. Let's say that you live in a house. In this house, you probably have a light switch somewhere. When the light switch is turned on, it activates a light fixture that lights up the room - similarly, when the light switch is flicked off, the room is dark.
Now, you might be thinking "So an RPG Maker switch is like a light switch". And you're right. Like a light switch, an RPG Maker switch has two states: ON and OFF. However, that analogy isn't just about the light switch. Let's say that you go to a hardware store and buy a switch. You can flick it on and off all day, and nothing will happen. You have to hook it up to wires and a light fixture before it actually does something. Similarly, in RPG Maker, switches are useless on their own - you have to hook them up to events in order to control them.
To summarize, an RPG Maker switch is like a light switch, in that it has two states: ON and OFF. Likewise, a switch by itself doesn't do anything - you have to have other events reference them to make them useful.
2. Anatomy of the Switch Operations window
(Note: I am using RPG Maker 2003, so my tutorial will be based on that particular iteration. I'm going to bet that switches are fairly similar in RPG Maker XP and VX, even if the windows look slightly different.)
So, now you know the basic concept of a switch. But how do you turn them on and off? Well, that's where the Switch Operations window comes in.
First of all, we'll need to create an event. In the main window of RPG Maker, select the "Edit The Event Layer" option. In RPG Maker 2003, it should look like a cursor in a yellow box. Alternatively, press the F7 key. Once you've done that, double-click on a square, which will open up the Event Editor window.
Now, double-click in the Event Commands window, the white portion that takes up most of the right side. Specifically, look for the <> symbol near the top of the white window. (You can click anywhere in the white portion for the same effect.) This opens up three (or four) pages of Event Commands. The one we're looking for is called "Switch Operations" or some variant thereof: in RPG Maker 2003, it's the sixth command on the left. Click that once.
This opens up the Switch Operations window. There's a number of options here, so I'm going to be going over each.
(Switch to Change heading)
-Single Switch: This will select the switch you want to turn ON or OFF. To select a switch, press the "..." box. This opens up yet another window, simply called "Switches". Here, you can select a switch, name them, and even increase the amount you have (the max is 5000). I highly recommend naming each switch something unique, as it makes later steps much easier.
-Switch Range: This allows you to turn multiple switches on or off at the same time. You can replicate the effects by using multiple Switch Operations commands, so I tend not to use it much. Plus, you have to select the range by the switch number, rather than name, so it's somewhat annoying if you're not exactly sure which ones you want to turn off.
-Variable Reference: This one is a bit tricky. It allows you to affect a switch based on a variable. Variables are a whole other thing entirely, but even if you know how to use variables, you probably won't use this much either - most of the time, it's just easier to use Single Switch.
(Operation heading)
-Turn ON: This takes the switch(es) selected under the previous heading and turns it ON. By default, all switches are OFF in an RPG Maker game, so if you use switches (and you will), you'll need to use this one a lot.
-Turn OFF: See above, but it turns it OFF instead. Turning an already-OFF switch OFF does nothing: if you want it to toggle between the two, that's for the next option:
-Toggle ON/OFF: This takes the selected switch(es) and reverses the setting: it turns OFF switches ON, and turns ON switches OFF. For the most part, you won't be using this a whole lot - it's mostly used for puzzles and the like. If you just want to turn a switch ON, use the Turn ON option - it might save you time in the long run.
That's the basic rundown of the window. (Again, depending on your version, there might be more or less options available.)
For the most part, you're going to be using the Switch Operations window to turn a single switch ON. So let's do that.
Select the Switch Operations command. Press the "..." button under the Single Switch option. Select switch 0001, name it "Test Switch", and press OK. Select "Turn ON" as the Operation, and press OK. If you haven't done anything else, the code in your event window should look something like:
<>Switch Operation: [0001:Test Switch] ON
So, we've turned a switch ON. Hooray for us! But like I said before, just turning a switch ON doesn't do a whole lot - you've got to hook it up to events to make it meaningful.
3. Switches in Action
So, we've established that we can have switches in both the ON and OFF setting. Following is 3 standard examples of how to use switches effectively - they're by no means the only way to use them, so experiment and see what works.
3a. Getting an item from a chest
So, you've created a dungeon. In this dungeon, you put a chest with, say, a Potion inside it. But, when you play the game, you can keep getting Potions from this chest indefinitely - you only want 1 potion to be in it. This is where Switches come in.
So, first off, create an Item Management command that adds a Potion to the party's inventory. Item Management is on page 1 of the Event Commands box, specifically the tenth option on the left. To add an item, select "Add Item" under the Operation heading, "Potion" (or whatever item you want) under the Specific Item heading, and "1" under the Specific Amount heading.
Next, create a Message (first option on the first page), and type "You got a Potion!" or something to that effect. You could also play a sound effect if you like.
Then, create a Switch Operations command. Under the "Single Switch" heading, select switch 0001 and name it "Potion Chest". (Again, I highly recommend giving appropriate names to all of your switches.) Select "Turn ON" under the Operation heading, and press OK.
So far, your code should look like this:
<>Change Items: Potion 1 Add
<>Message: You got a Potion!
<>Switch Operation: [0001:Potion Chest] ON
Now, on the top of the Event window, there should be a button labeled "New Page". Press that, and a new, blank page will appear - it should be page 2. On this new page, look at the left of the window - there's a bunch of check boxes under the "Preconditions" heading. Select the first option, which should be labeled "Switch". Press the "..." button, and select the "Potion Chest" switch we used in the last page. Leave the Event Commands window empty, or if you like, you can put a Message that says "Empty". (This page will display after getting the item from the chest, so you can do whatever you like to signify that you can't get items from it.)
And that's it! With that done, you've created a chest that you can get 1 and only 1 Potion from, no matter when you do it.
3b. NPCs
So, in your game, let's say that there's a town with non-player characters (NPCs) in it. You want them to say different things depending on how far you are in the game: for example, one guy says "Welcome to Corneria!" at the beginning of the game, but he also comments on your deeds as heroes.
So, let's take the knowledge of making a one-use chest and apply it to other things. Let's say that, for example, you defeat a monster. You want the monster to disappear after you fight it once. You can use the same basic idea to make a monster you only have to fight once - after the monster encounter, just turn a switch ON, create a new page with no code, and make sure one of the preconditions is that specific switch being ON. (You'll also want to set the graphic of the event to something blank, and set the "Event Layer" to Below Hero so you can move past it once it's defeated.)
Just as an example, here's what your monster event should look like:
<>Message: Blarg I am a monster.
<>Enemy Encounter: Normal, Monster
<>Message: Oh noes I am dead.
<>Switch Operation: [0002:Dead Monster] ON
(Note: Make sure you use a different switch here than in the Potion Chest event above. Check section 4 for more info.)
Now, let's go back to the NPC. In his event, make page 1 a Message saying "Welcome to Corneria!" or whatever. Don't activate a switch here.
Next, create a new page, Make the precondition "Switch [0002:Dead Monster] ON". In page 2, create another Message that says "Wow, you slayed the Monster? You're awesome!"
You can repeat this with any number of switches. For example, after, say, defeating a Dark Lord and turning a switch ON there, you can go back to this NPC event, make another new page with that switch as the precondition, and have another message saying "You guys are great!".
The important part here is
priority
. In an RPG Maker event with multiple pages, the numerically highest page with fulfilled preconditions is the one that activates. So, if page 1 and page 2 have the same preconditions, page 2 is the one that will always activate - if you want page 1 to activate, you'll have to change the preconditions of page 2 so that page 1 activates it.
3c. Switches and Conditional Branches
Conditional Branches are something I'll probably get to later. Essentially, they're like the page preconditions we're already familiar with, but more useful - you can have any number of conditional branches (rather than being limited to two), and they can check if a switch is ON
or
OFF.
So let's make a simple puzzle with conditional branches and switches. Let's make a door surrounded by four switches. Switches 1, 2 and 4 have to be ON and switch 3 has to be OFF in order for the door to open.
First of all, create an event. Set the graphic to a lever or something (it doesn't really matter). For Event Commands, play a sound effect of a click (Play Sound Effect is located on the 3rd page of Event Commands), then create a Switch Operation that toggles a switch called "Switch1" ON/OFF.
Now, copy that entire page (the Copy Page button is right next to the New Page button) and paste it. Don't change the Event Commands, but make the preconditions "Switch1 ON", and change the graphic so that it indicates it's in a different state (lever is in a different position, button is pressed in, etc.)
Next, create three more events exactly like the first. Make sure they all use different switches.
Finally, the door. What we're going to do here is create four Conditional Branches, nested within one another. The Conditional Branch command is on the third page, fifth from the top on the right. The first option checks for switches, so don't change that. Click the "..." button and make sure one of the switches you used in the puzzle is selected, and set it to ON. Deselect the "Execute Custom Handler if Condition is Not Met" button near the bottom, and press OK.
<>Branch if Switch[0010:Switch1] is ON
<>
<>End
<>
Now, create another branch within that branch, with the second switch set to ON. Inside that branch, create another that checks if the third switch is OFF, and inside that, create one more that checks if the fourth switch is ON.
<>Branch if Switch[0010:Switch1] is ON
<>Branch if Switch[0011:Switch2] is ON
<>Branch if Switch[0012:Switch3] is OFF
<>Branch if Switch[0013:Switch4] is ON
<>
<>End
<>
<>End
<>
<>End
<>
<>End
<>
Finally, create a Switch Operation command in the Switch4 branch that turns Switch5 ON. Then create a new page with Switch5 ON as the precondition, and leave the Event Commands blank. This way, once the puzzle is solved correctly, you don't have to solve it again. (Or, if you want to have to solve it every time you exit and enter the room, don't turn Switch5 ON. It's up to you.)
And that's it! A simple switch puzzle.
4. Other
If you did all three of my examples, you might have noticed that I said to use different switches every time. Unfortunately, you have to use a unique switch for every event - so if you have 100 treasure chests in the game, you have to use 100 unique switches. That's just the way it is. But the upper limit for switches is 5000 (you can use the "Switch Array" button to increase how many switches you have at a time), and you probably won't get close to that. So don't worry too much - just make sure to use a different switch every time.
And that's about it! Experiment with switches and see what you can come up with!
Next time: Variables. Hoo boy, that's gonna be a tutorial.
Logged
Blog:
The Gigaverse
Twitter:
Initial Chaos
SaiKar
KOFFING!
Staff
Royal
Posts: 4,082
Re: Switches: A Basic Guide
«
Reply #1 on:
May 31, 2011, 07:41:01 PM »
Even if we did, at least we have this one now.
Good tutorial. Maybe add a few pictures though to illustrate some of the points better?
Logged
WarxePB
Action Sue
Royal
Posts: 3,601
What killed the dinosaurs?
Re: Switches: A Basic Guide
«
Reply #2 on:
May 31, 2011, 07:47:40 PM »
Lucas: Yeah (in fact I think I wrote one before), but it's lost in the mists of time and this one's better.
Sai: Yeah, I probably should. The event editors are pretty similar in every version, right?
Logged
Blog:
The Gigaverse
Twitter:
Initial Chaos
SaiKar
KOFFING!
Staff
Royal
Posts: 4,082
Re: Switches: A Basic Guide
«
Reply #3 on:
May 31, 2011, 08:46:04 PM »
They are very close. Some of the names vary, but honestly that could be just translation issues between the people that haxxed them. The actual event script menus look very similar.
Logged
Print
Pages: [
1
]
« previous
next »
Charas-Project
»
Game Creation
»
Requests
»
RPG Maker Programming
»
Switches: A Basic Guide