Jon LaJoie"Is there life after death, or does everything just suddenly stop one day, like my ability to get an erection did?"
Check out the site too!
| Entertainment
| Game Making
| Creative Forum
| Technology & Computers
| Translations
![]() ![]() |
Nov 9 2004, 03:25 PM
Post
#1
|
||
![]() Administrator of this Asylum AdminMember No.: 1 Joined: 8-November 04 Posts: 2,478 --> From: Longueuil, Canada RPG Maker Level: Master Class Title: Writer, Scripter & Designer Last.fm ID: Dubealex Country: ![]() |
RMXP Switches & Local Switches Demystified
(1) Introduction This class will teach you absolutely everything that you need to know to understand and efficiently uses RMXP Switches and Local Switches. (2) Introduction to Switches in general What is a switch ? In RPG Maker XP, a switch is a kind of "trigger" that is used to set something ON or OFF depending on the situation. To start up clear on something you must know, I must say a switch is in fact a type of variable. In RPG Maker XP point & click environment (the Event Commands), you will not really notice that; as you can just set a switch ON or OFF. But a switch, in the background, is seen as a normal variable. Here an extract of my variable class: QUOTE - Definition of "Variable": able or liable to change. Variables are used in every games and softwares; they store information, information that is then used by the system. We could say that a variable is a box in wich we want to put something for later use. What kind of information ? This can be divided into 4 major groups: 1 - Numbers 2 - Text 3 - Boolean 4 - Arrays [...] "Boolean" variable are triggers, they can only be TRUE or FALSE. Meaning they can contains only 1 value, and you have only the choices between TRUE or FALSE. In RPG Maker XP, a "Switch" is actually a "Boolean" variable; it can be wether ON or OFF. [...] So remember that, since we will talk about switches in Ruby in later chapters. Now let's continue in for the simple stuff: What is a "Local Switch" then ? A normal switch can be set ON or OFF from any events you created on the map, and a Local Switch is a switch available to use only in one particular event. Every event that you create in RPG Maker XP will have 4 local switches; we could say that those local switches are actually "Private Switches" that can be modified only from within the events that they exist in. Those "Local Switches" are named A, B, C and D. (You cannot change their names like you changes normal switch.) So, in brief, remember this: Normal Switch: A normal switch is available for every events in your game, and can be modified from any events in your game. This is a "Global Switch". Local Switch: A local switch exist only within a particular events, and each events have their own private switches, 4 to be exact. Here's a diagram about switches in RMXP (Wich explains the structure of switches and local switches in your project):
switch5.jpg ( 39.75k )
Number of downloads: 1330So, as you can see, in RPG Maker, every normal switches are available to every events in your game. This means that if you set a precondition on 100 events on 100 different maps, and you choose the same switch for all of them, setting this switch ON will activate all those events. You can also see that local switches are confined to only one event, and that every event have its own "pack" of local switches. (3) RMXP Switches System
switch1.jpg ( 20.85k )
Number of downloads: 927--> IMPORTANT ABOUT SWITCHES: Switches in RPG Maker XP are recognized by the system only by their ID numbers, not by their names. Meaning that you could have 2 switches having the same name, but never the same ID. When naming a switch, always try your best to name it with something that would reflect it's usage. I.E: If you are using a switch to end a story that was auto-started by an event, you could call it "Story-End". 1) Specific Switch Using this option will allow you to choose one switch from your database with the selector to the right. (If you want more switches, click on the button "Array Size" to the bottom left of the window that appears when you choose a switch, and enter the number you want. Maximum is 5000.) 2) Switch Range This option will allow you to modify many switches at the same time. When you choose this, you must enter the switches ID in the selection box to the right. Meaning that if you write switch ID 15 in the first and switch ID 25 in the second, the operation you will do will affect switches 15 to 25 included. 3) Operation This is pretty simple, as we have said earlier, a switch can only be ON or OFF, so you choose here if you want to turn it ON or OFF. (4) RMXP Local Switches System
switch2.jpg ( 9.8k )
Number of downloads: 5861) Local Switch You can choose wich local switch you want to modify, as we said earlier, every event have their own 4 local switches known as A, B, C and D. 2) Operation This is pretty simple, as we have said earlier, a switch can only be ON or OFF, so you choose here if you want to turn it ON or OFF. (5) How to use switches & local switches In this chapter we will learn how to manipulate switches, and we will also see some example on basic stuff like chest and events activation. First thing first, you must be able to activate an event with a switch; once you understood how this works, you will understand pretty much anything else related to switches. A) Event Activation First of all, we will name our 2 events so we know wich is wich: The event that will activate the other will be named "Caller" and the one who will be activated by "Caller" will be named "Sleeper". (Pretty straigh-forward...) In our case, we will create the event "Sleeper" first. I won't do a complete Event tutorial here, but I will explain what you must know to understand switches now:
switch3.jpg ( 30.62k )
Number of downloads: 12081) Name This is where you write the name of the event; it is only relevant to you, RPG Maker will never uses this information. So our first event is named "Sleeper." 2) Preconditions That section covers the preconditions. This means that you can choose here the conditions needed for this event page to be "active". For the present situation, we will talk about the Switch precondition. If you choose a switch here, it will have to be ON in order for the events to be active. 3) Event Commands That section will contains all the actions the event will do when activated. In our situation, the first page is empty because by default, we want "Sleeper" to be inactive and "Sleep". Event Pages: As seen in the picture above, we used 2 page for "Sleeper". You can create a maximum of 99 pages per events, each pages being a different variation of the same event. (More about that in later chapters.) You can then set different "Preconditions" and "Event Commands" in many different pages. So our first page is empty, and our second will contains the actions we want "Sleeper" to do when activated. Look:
switch4.jpg ( 30.6k )
Number of downloads: 1146As you can see, we simply created a second page, added a message in the Event Commands, and set the preconditions to a switch that we named "Wake-Up". (Because its purpose is to wake sleeper up.) By default, every switches are OFF, so our event "Sleeper" will do nothing until our switch "Wake-Up" is set ON. Now is the time to create our event "Caller". Create a new event, and in the event commands, do a Switch Operation and set the switch "Wake-Up" ON. Now, if you test play that game, if you go talk to "Sleeper", nothing happen. Go talk to "Caller", the switch "Wake-up" is now ON -- Wich means "Sleeper" has been activated, if you go talk to him, he will tell you something. B) Creating a treasure chest By creating a treasure chest, you will see how to use local switches. Local switches are very useful for small event like doors, chest and interactive NPC who tells different things. They are useful because it saves normal switches for "real" events; just imagine having 500 treasure chest in your game, and imagine you would need 500 switches for them... Who could remember where his chest #54 was ? Local Switches are an efficient way of doing those kind of event that repeats themselves a lot in your game. We don't need a picture for this, since you can clearly see what we will use in the picture used above. In the first page, we will make the treasure chest opens, give 100 gold pieces to the player, and activate a local switch that will prevent the player from opening the chest another time. To make the chest opens, I uses "Move Events"... Because a chest is in a character set in the default resources of RPG Maker XP. The move event will look like this:
switch6.jpg ( 49.18k )
Number of downloads: 1520As you can see, this event must be set as "Lock Facing", this is because RPG Maker will, by default, turn the graphic of an event toward the player. If you talk to the treasure chest from the left, the chest will try to face you, and will thus face left. We do not want this to happen because it would change the way the chest look like, so we checked the option "Lock Facing". The move event contains an SE for the chest that opens, and we set "Lock Facing" to OFF while we changes the graphics of the chest; otherwise it would not look like its opening. Then, after the move event, we must set "Lock Facing" back ON. The "Wait 10 frames" will make a small pause between the end of the move event and the message "Received 100 GP !". (10 frames = 1 sec) We played another SE that simulate a "success" song because you gained something, we used a message event to tell the player what he gained, and we did a "Change Money" operation to give the player 100 GP. Lastly, we set the Local Switch A to ON. On our second page, we have set the graphic to the one of an opened chest, and we have set the preconditions to the Local Switch A. Then, the player won't be able to open it again. (6) Events Page Priority In RPG Maker, every events can have up to 99 pages, each being able to have different event commands and preconditions. There is a priority order in those pages. Here's how it works: The higher page number have priority on all those below them. Meaning that Page #2 have priority on Page #1, and that Page #3 have priority on Page #1 and 2. All this means that if you create an event with 4 pages, and set the same switch precondition on all of the pages, RPG Maker will uses the highest page number available. It also means that if you used switch #1 as precondition on page #1, and that you used switch #2 as precondition on page #2, if both switches are ON, only page #2 will be active as it have priority on the other page below. (7) Switches within Ruby Script You can set your switches ON and OFF within the Script Editor or in a Call Script using the following syntax: CODE $game_switches[id#] = flag value Where [ID#] represent the ID of the switch you want to manipulate, and flag value is wether "true" or "false" -- ON is "true" and OFF is "false". So, it would look like this: CODE $game_switches[1] = true Will set the game switch ID# 1 ON. You can found more infos about those syntax in my RGSS Reference. (8) Local Switches within Ruby Script You can also set any local switches of any events on any map ON or OFF from any event on any map using the following syntax in a call script, or the script editor: CODE $game_self_switches={[MAP-ID, EVENT-ID ,"LOCAL-SWITCH"] =>flag} $game_map.need_refresh = true Where MAP-ID is the ID of the map where the event is, EVENT-ID is the actual event ID, and LOCAL-SWITCH is wether A, B, C or D. flag is wether true or false, as for normal switches. So, as example, if you want to set the local switch A for events ID#12 on map ID# 2 to ON, you would write this in a call script: CODE $game_self_switches={[2, 12 ,"A"] =>true} $game_map.need_refresh = true The line "$game_map.need_refresh = true" is there to ensure that the map is refreshed after changing the value in the hash (the local switch) because if we do not, the changes made to a local switch from an event on the current map would not show instantly. Have fun with that ! Now you have all the power in your hands, so go create a good game ! (9) Conclusion Feel free to post any questions or comments ! This post has been edited by Dubealex: Nov 7 2005, 10:06 PM |
|
|
|
||
May 1 2005, 09:36 AM
Post
#2
|
|
|
Newbie NewbieMember No.: 566 Joined: 1-May 05 Posts: 1 --> RPG Maker Level: I'm almost getting it Class Title: Verry Bad Game Creator |
Yo thanx youve just helped me makeing about 5 games so thanx
Haden |
|
|
|
May 2 2005, 01:46 AM
Post
#3
|
||
![]() Wow, a custom title. How'd he do that? Game Making SupportMember No.: 543 Joined: 25-April 05 Posts: 3,044 --> From: Gothenburg, Sweden RPG Maker Level: Expert Class Title: Scripter Country: ![]() |
Thanks alot! You just taught me how to manage local switches and normal switches through RGSS!
|
|
|
|
||
Mar 26 2006, 03:46 AM
Post
#4
|
||
![]() Master MasterMember No.: 2,406 Joined: 22-January 06 Posts: 587 --> RPG Maker Level: Getting good Class Title: Scripter, Eventer Country: ![]() |
About this:
QUOTE(Dubealex) Local Switches Syntax & Example: CODE $game_self_switches={[MAP-ID, EVENT-ID ,"LOCAL-SWITCH"] =>flag} $game_map.need_refresh = true Doing this would clear any other local switch as you're setting the $game_self_switches to be that one defined switch thereby deleting any other self-switch present. If you only want to change or add, not remove anything else, it should be like this: CODE $game_self_switches[[MAP-ID, EVENT-ID, "LOCAL-SWITCH"]] = flag value
$game_map.need_refresh = true |
|
|
|
||
Jun 17 2006, 05:26 AM
Post
#5
|
|
![]() Newbie NewbieMember No.: 3,499 Joined: 17-June 06 Posts: 12 --> RPG Maker Level: Getting good Class Title: Mapper |
I dont get it... tried making a chest, doesnt work... and i need to learn switches, for my game...
Games |
|
|
|
Nov 12 2006, 02:17 PM
Post
#6
|
|
|
Newbie NewbieMember No.: 5,259 Joined: 12-November 06 Posts: 6 --> RPG Maker Level: Getting good Class Title: Gamer maker i guess |
wow. that was a GREAT tutorial, this makes life so much easier/possible
THANKS! |
|
|
|
Nov 13 2006, 07:38 PM
Post
#7
|
||
|
Newbie NewbieMember No.: 5,262 Joined: 13-November 06 Posts: 13 --> RPG Maker Level: Fair |
This is great!
|
|
|
|
||
Dec 9 2006, 05:33 PM
Post
#8
|
||
![]() God GodMember No.: 5,137 Joined: 28-October 06 Posts: 908 --> From: Boston, Massachusetts. RPG Maker Level: Novice Class Title: Writer, Reviewer, Beginner Eventer, Graphic Artist. |
Definetly helpful! I'll be sure to save this Tut somewhere safe.
|
|
|
|
||
Mar 11 2007, 09:29 PM
Post
#9
|
|
|
Newbie NewbieMember No.: 7,218 Joined: 6-March 07 Posts: 1 --> From: Puerto Rico RPG Maker Level: I'm almost getting it Class Title: Writer and Spriter |
Thank you very much, Dubealex. Now I understand switches much better. I managed to fix a few events I couldn't get to work right.
Do you know of any tutorials that explain how to use every event command? I have doubts with the Choice Handlers. I want certain message to appear with certain option, but it's not working, and I don't know what to do. Any links would be appreciated. Thank you! This post has been edited by Arwym Starlight: Mar 11 2007, 09:30 PM |
|
|
|
Jun 26 2007, 12:31 PM
Post
#10
|
||
![]() Newbie NewbieMember No.: 9,293 Joined: 26-June 07 Posts: 2 --> RPG Maker Level: Novice Class Title: Noob Country: ![]() |
Great tutorial, I managed to fix a few things. What I'm having trouble with is having a room stay the same when you leave and come back, is that possible?
|
|
|
|
||
Oct 7 2007, 08:23 AM
Post
#11
|
|
![]() Member MemberMember No.: 11,492 Joined: 7-October 07 Posts: 51 --> From: *sigh* RPG Maker Level: Getting good Class Title: Writer, Developer Country: ![]() |
I now Finally Know how Switches work ^^ Thank you Dubealex
I only Still Don't get the Local Switches but I will try till I know it |
|
|
|
Oct 26 2007, 02:32 PM
Post
#12
|
|
|
Newbie NewbieMember No.: 11,856 Joined: 26-October 07 Posts: 2 --> RPG Maker Level: I'm almost getting it |
I got a problem. I'm trying to make a locked door that requires a key to open but it is opening without they key.
I set up a door with the duduct item command(the key being the item) and then a switch on command afterwards. Then I make a 2nd tab and have it where the door will open for me to move to the next room. If I press enter once, it takes me to tab 2 and if I hit enter again, door opens. It will only deduct my key if I have one but if I don't, it just skips that step and moves on to tab 2 to open the door and take me to the next location. |
|
|
|
Oct 26 2007, 03:41 PM
Post
#13
|
||
![]() ...meh... Asylum Editorial TeamMember No.: 4,335 Joined: 7-August 06 Posts: 3,766 --> From: Hue RPG Maker Level: Master Class Title: Scripting Nerd Country: ![]() |
The open door should be the first tab, and the requirement to open the door should be second. Because the way an event looks at stuff, it always starts with the last tab and works backwards.
|
|
|
|
||
Oct 26 2007, 04:02 PM
Post
#14
|
|
|
Newbie NewbieMember No.: 11,856 Joined: 26-October 07 Posts: 2 --> RPG Maker Level: I'm almost getting it |
Yeah but now it is like this with the switch box checked on the first tab.
Tab 2: Call common event(deduct the key from inventory) Control Switch 0001 = ON Tab 1: Transfer player to other location Results: Nothing It used to be like this with the switch check box on the 2nd tab. Tab 1: Call common event(deduct the key from inventory) Control Switch 0001 = ON Tab 2: Transfer player to other location Results: Me able to go through the door without having to insert the key Things still aren't working right. Gubid, or anyone else, could you tell me what is doing wrong? I did check the switch box on the 1st tab and then I was told to not check the first tab and so I did the 2nd tab. I also did the same with self switch and that didn't work either. EDIT: Never mind guys, I did what I was looking for just right.[attachment=6258:help1.JPG] This post has been edited by Sin86: Oct 26 2007, 09:02 PM |
|
|
|
Dec 30 2007, 11:41 PM
Post
#15
|
|
![]() Newbie NewbieMember No.: 4,308 Joined: 5-August 06 Posts: 6 --> From: Third Door On The Right RPG Maker Level: Getting good |
Is there some way to check which local switches are turned on for several events inside of another event? For example: See if local switch A, B, or C is On for events 1-5 inside of event 6? Hopefully that makes sense.
|
|
|
|
Dec 31 2007, 05:19 PM
Post
#16
|
||
![]() "\ ';..;' /" GodMember No.: 1,130 Joined: 12-July 05 Posts: 1,371 --> From: San José, Costa Rica RPG Maker Level: Master Class Title: Random noob Country: ![]() |
Should be like this:
CODE on = false 1.upto(5) do |i| ['A', 'B', 'C'].each do |j| on |= $game_self_switches[ [$game_map.map_id, i, j] ] end end return on if the local switches A, B or C of any of those events (1 to 5) is on, the variable on will be true.
|
|
|
|
||
Dec 31 2007, 07:00 PM
Post
#17
|
|
![]() Newbie NewbieMember No.: 4,308 Joined: 5-August 06 Posts: 6 --> From: Third Door On The Right RPG Maker Level: Getting good |
if the local switches A, B or C of any of those events (1 to 5) is on, the variable on will be true. Does that mean there only needs to be 1 local switch on out of the possible 5 for the variable to be true? If that's the case that won't work. Basically, what I'm doing (or trying to do) is setting up a dungeon puzzle with a series of levers. Each lever needs to be set in a certain position, sort of a combination lock. For each lever, there's a local switch being used for each position (A=Left B=Middle and C=Right). After adjusting the "combination" levers, there is a master lever to check if the combination is correct and allow the player out of the dungeon if it is. So I need a way of checking for certain orders of A,B,Cs from the other levers. I know I could make this work with regular switches or variables, I'm just trying to use the local switches because they otherwise wouldn't be used and I'd like to save the regular switches in case I need them later. Got a lot of game to go, heh. |
|
|
|
Jun 15 2009, 09:48 PM
Post
#18
|
|
|
Newbie NewbieMember No.: 17,217 Joined: 15-June 09 Posts: 1 --> RPG Maker Level: Not Applicable Country: ![]() |
Thanks for your posts. They are really very cool, very wonderful
simulationcredit This post has been edited by verra99: Jun 15 2009, 09:48 PM |
|
|
|
Nov 29 2009, 10:31 AM
Post
#19
|
||
![]() Newbie NewbieMember No.: 18,431 Joined: 29-November 09 Posts: 5 --> From: Netherlands RPG Maker Level: I'm almost getting it Class Title: Writer, Spriter, learning to script Country: ![]() |
I know it's an old topic but.. I have a problem..
I downloaded a script, and these are the instructions: # Instructions: # Place script above main, but below other default scripts. # On each map you want the tint set by this script, make an event as follows: # [Parallel Process Event] # Turn on switch 3 # Loop # Script... Check_Time.new # Wait 1 frame # End Loop So when I've insert the script, I have to make an event with a Parallel Process. And on the first page I have to turn on the switch "0003: <name>" ? |
|
|
|
||
Nov 29 2009, 12:39 PM
Post
#20
|
||
![]() ...meh... Asylum Editorial TeamMember No.: 4,335 Joined: 7-August 06 Posts: 3,766 --> From: Hue RPG Maker Level: Master Class Title: Scripting Nerd Country: ![]() |
No, I dont think you have it turn switch3, but rather require switch 3, but that is just from reading what you posted. I would highly recommend you take this to the script topic as they will be able to help you more.
|
|
|
|
||
![]() ![]() |
The Staff Team |
Lo-Fi Version | Time is now: 3rd September 2010 - 03:05 AM |