• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Setting Self Switch in one map from another map

Derxwna Kapsyla

Derxwna "The Badman" Kapsyla
437
Posts
12
Years
The current version of pbSetSelfSwitch is a really good addition to Pokemon Essentials, as it allows you to remotely set the self switch of an event. This nullifies the need to make another global switch which only effects 1 solitary event. The only downside to it was that it only worked locally, within the same map. Sometimes, you needed an event which did something, but only after you were many maps away, and would be solved much easier with a Self Switch than a Global Switch, as it would only effect that one event. Not to mention, RPG Maker XP has a limit of 999 Global Switches, and after that you can't create anymore. If you have your entire Global Switches filled up with switches that effect one event and only one event, on a repetitive basis, you'll eventually find yourself running short on space for switches when you need them.
While I was messing around with RPG Maker VX Ace, I found a script that allowed you set the Self Switch of an event from anywhere to any event across the game. This was a much useful, and I had asked my friend if he could figure out how to reverse-engineer (if that's the right term) the script so it would would in RPG Maker XP. Fortunately, the process was so simple that reverse-engineering wasn't really needed.
Code:
# Sets another event's self switch (eg. pbSetSelfSwitch(20,"A",true) ).
# To be used in a script event command.
  def pbSetSelfSwitch(event,swtch,value)
    $game_self_switches[[@map_id,event,swtch]]=value
    $game_map.need_refresh = true
  end
The above script is the original script, the one used to set Self Switches across the map its in.
Code:
  def pbSetSelfSwitch2(map,event,swtch,value)
    $game_self_switches[[map,event,swtch]]=value
    $game_map.need_refresh = true
  end
This script changes @map_id so that it's an actual variable and not dependent on the map you're currently on. This script, however, cannot replace the original one, as it will break areas where you've currently used pbSetSelfSwitch. The script has been tested, and is shown to remain in effect even after you leave the maps where the event was set and the map where the set event was. The script should be placed below the original, in the PokemonMessages script section, around Line 364.

Hopefully you find a use for this script, I know it's going to be useful to me.
If used, you should probably give credit to Mugendai/DoctorInfinity for this, as he's the one who modified it to work across the game.
Maruno why wasn't this in Essentials by default?
 

Black Eternity

Lord of Eternity
57
Posts
11
Years
  • Age 31
  • Seen Jun 30, 2016
Thank you for sharing this!
One thing you should note, "for beginners", to actually use it in an event...

pbSetSelfSwitch2(MAP ID,EVENT ID,SWITCH,TRUE/FALSE)
Map ID = Going to map list on the side, right click and select "Map Properties" (ID:###)
Event ID = When editing event you will also see "ID:###"
Switch = "A,B,C,D"
True/False = .............

an full example:
pbSetSelfSwitch2(5,19,"A",true)

Also, make sure not to place these events too close to the edge of the map,
as it will not be refreshed until upon entering the map. (Can still see the event from other map)

Just trying to make it easier. I am a noob. :P
 

Sir_Tman

Overworked game Dev
201
Posts
8
Years
I know this threads old but I putting this here because you don't need to add this script all you need to do in an event in a script box just put

$game_self_switches[[MAP ID,EVENT ID,"The Switch"]]=Value(i.e. true or false)

Example
$game_self_switches[[92,7,"A"]]=true
 
4
Posts
4
Years
  • Age 29
  • Seen Oct 29, 2023
Thanks for this!
It will be so usefull!
I have a question related to this. It would be possible a script like the 'pbSetSelfSwitch' normally used, where for example, you can switch on the 'A' switch for 10 events? All in the same script.
Thanks again for the contribution!
 

Derxwna Kapsyla

Derxwna "The Badman" Kapsyla
437
Posts
12
Years
If you're asking whether it's possible to do something like pbSetSelfSwitch([10,11,12,13,14,15,16,17,18,19,20],"A",true), I'm not sure if that's functionally possible. You can still just do this in one script event:
Code:
pbSetSelfSwitch(10,"A",true)
pbSetSelfSwitch(11,"A",true)
pbSetSelfSwitch(12,"A",true)
pbSetSelfSwitch(13,"A",true)
pbSetSelfSwitch(14,"A",true)
pbSetSelfSwitch(15,"A",true)
pbSetSelfSwitch(16,"A",true)
pbSetSelfSwitch(17,"A",true)
pbSetSelfSwitch(18,"A",true)
pbSetSelfSwitch(19,"A",true)
pbSetSelfSwitch(20,"A",true)

Same thing will work for pbSetSelfSwitch2, just add in the map id where necessary.
 
233
Posts
5
Years
  • Age 33
  • Seen Oct 9, 2023
If you're asking whether it's possible to do something like pbSetSelfSwitch([10,11,12,13,14,15,16,17,18,19,20],"A",true), I'm not sure if that's functionally possible. You can still just do this in one script event:
Code:
pbSetSelfSwitch(10,"A",true)
pbSetSelfSwitch(11,"A",true)
pbSetSelfSwitch(12,"A",true)
pbSetSelfSwitch(13,"A",true)
pbSetSelfSwitch(14,"A",true)
pbSetSelfSwitch(15,"A",true)
pbSetSelfSwitch(16,"A",true)
pbSetSelfSwitch(17,"A",true)
pbSetSelfSwitch(18,"A",true)
pbSetSelfSwitch(19,"A",true)
pbSetSelfSwitch(20,"A",true)

Same thing will work for pbSetSelfSwitch2, just add in the map id where necessary.

If the event IDs are all sequential, then this is an easier way to do it:
Code:
for i in 10..20
  pbSetSelfSwitch(i, "A", true)
end



Thanks for this!
It will be so usefull!
I have a question related to this. It would be possible a script like the 'pbSetSelfSwitch' normally used, where for example, you can switch on the 'A' switch for 10 events? All in the same script.
Thanks again for the contribution!

If your event IDs are all in a row, then you can use the above code (it goes from ID 10 to 20, obviously change those numbers if needed). In case they aren't sequential, you can make an array of all the event IDs that you need to set self switch for like so:

Code:
event_ids = [10, 20, 30] // Change these values as needed
for i in event_ids
  pbSetSelfSwitch(i, "A", true)
end

This code sets self switch A for events 10, 20, and 30 - again, change or add values as needed.
 

Derxwna Kapsyla

Derxwna "The Badman" Kapsyla
437
Posts
12
Years
Well, that's definitely stuff I'm going to have to remember for the future! Something like this might be useful for resetting all self switch flags on every map, which is something I've been trying to figure out how to do for a while...
 
13
Posts
1
Years
  • Age 22
  • Seen Sep 17, 2022
The current version of pbSetSelfSwitch is a really good addition to Pokemon Essentials, as it allows you to remotely set the self switch of an event. This nullifies the need to make another global switch which only effects 1 solitary event. The only downside to it was that it only worked locally, within the same map. Sometimes, you needed an event which did something, but only after you were many maps away, and would be solved much easier with a Self Switch than a Global Switch, as it would only effect that one event. Not to mention, RPG Maker XP has a limit of 999 Global Switches, and after that you can't create anymore. If you have your entire Global Switches filled up with switches that effect one event and only one event, on a repetitive basis, you'll eventually find yourself running short on space for switches when you need them.
While I was messing around with RPG Maker VX Ace, I found a script that allowed you set the Self Switch of an event from anywhere to any event across the game. This was a much useful, and I had asked my friend if he could figure out how to reverse-engineer (if that's the right term) the script so it would would in RPG Maker XP. Fortunately, the process was so simple that reverse-engineering wasn't really needed.
Code:
# Sets another event's self switch (eg. pbSetSelfSwitch(20,"A",true) ).
# To be used in a script event command.
  def pbSetSelfSwitch(event,swtch,value)
    $game_self_switches[[@map_id,event,swtch]]=value
    $game_map.need_refresh = true
  end
The above script is the original script, the one used to set Self Switches across the map its in.
Code:
  def pbSetSelfSwitch2(map,event,swtch,value)
    $game_self_switches[[map,event,swtch]]=value
    $game_map.need_refresh = true
  end
This script changes @map_id so that it's an actual variable and not dependent on the map you're currently on. This script, however, cannot replace the original one, as it will break areas where you've currently used pbSetSelfSwitch. The script has been tested, and is shown to remain in effect even after you leave the maps where the event was set and the map where the set event was. The script should be placed below the original, in the PokemonMessages script section, around Line 364.

Hopefully you find a use for this script, I know it's going to be useful to me.
If used, you should probably give credit to Mugendai/DoctorInfinity for this, as he's the one who modified it to work across the game.
Maruno why wasn't this in Essentials by default?

I use version 20.1 of Essentials and I can't find the original pbSetSelfEvent script since I can't find it in "Messages".

EDIT: solved immediately is found in Interpreter on line 335
 
Last edited:
Back
Top