RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Solved][VXA] Change all Self Switches on a Map / Event Graphic Changes

0 Members and 2 Guests are viewing this topic.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
I wasn't sure whether to put this in "events" or "scripts". ;9 I don't know if it requires any additional scripting or not. I'm working on a farming system (finally!). It took me forever to get the graphic changes down and now I'm stuck with a system that is going to be a bit complicated. My question is -  "is there a better way to do this?"

What I'm trying to do:

Using PK8's "event self variables" script, I was able to store two variables for each square of soil (event) - one for the "type" of crop planted, and one for the "growth" stage. The "growth" variable will increase by 1 everyday after that crop is planted, until it reaches it's maximum and can be harvested. For example, at stage 3 "growth", a Turnip "type" crop will be ready to be harvested. It differs for each plant.

Along the way of the growth cycle, I have the event change graphics, to signify the event growing. A Turnip at stage 1 will look like seeds, stage 2 will look like a stub, and stage 3 will be a full-grown turnip. I was also going to bring in a "watering" system, but I first need to get down the basics.

The Problem:

First, I tried to have the event simply "change graphics" via the move route command in Ace. However, when you exit the map and return, the graphics reset to the default event page graphic. Okay, got it. That's normal. If there were a way to make that permanent, that would be amazing. ;_; But I don't know if its possible.

Next, I tried to have the event run as a parallel process to check the stage of growth, change the graphic via move route, and then "erase event" so it would replay the event every time you enter the map. But erasing the event got rid of the graphic entirely. Not erasing the parallel process caused a severe drop in FPS. ;9

So, I then tried to run the parallel, change the graphics, and then use a self switch to stop it. But then the graphic changes to whatever the self switch event page is set to. I would try to use self switches to alternate between each stage, but I don't quite have enough self switches - at least not ones that can be used with the automatic "conditions" box. The script I'm using allows more, but I don't know how I'd call those via event condition. Overall, it's not preferred because it would give me a lot of event pages. ;_; I wish there were some way to use the graphics change movement command instead.

What I ended up doing:

Each "plot" is set up in a way, thanks to PK8's script, where it stores its own variables without me having to specify which event to store them to. It can simply just say "use the event we're on right now". So, I can literally just copy and paste that plot of land and make as many as I want. :-) But since I can't manage to make the graphical changes run by "use the event we're on right now", I had to set it through another event entirely. So, this event has to check and see what each individual plot's planted plant type is, check it's growth, and then change its graphic.

I guess I was wondering if there was any way to bypass having to use a third party event, and instead have the graphical changes go through the events used for the plots themselves. That way, I can just have stuff set to "this event", instead of "event 1", "event 2" ... etc.

If anyone has any ideas, I would appreciate the help very much. ;_; Thank you, guys. Sorry about the long post.
« Last Edit: August 30, 2014, 01:14:14 AM by yuyu! »
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Quote
But since I can't manage to make the graphical changes run by "use the event we're on right now", I had to set it through another event entirely.
Why can't you do that exactly? I think it would be helpful to have a picture of the current layout so we can get a better understanding.

***
Rep:
Level 39
RMRK Junior
I don't know if it's even worth scripting (since it might be just as complicated) but I can have a look at finding a script fix for you once I finish with some other requests!

I don't understand exactly what the problem is, since I read it too quickly :p but I'm sure we can figure something out.

I don't know if this would be helpful, but Shaz has a script that clones events, so that if you want to use the same event twice, instead of having to change them both to make a different effect, you just have to change the "base event" and the clones will also change. I can link you to that if that would be helpful.
My Website:

:tinysmile:

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Thanks for the replies! Sorry for being confusing, though. ;9

@Euphoria - I considered a clone event script at first, but I don't think the system quite needs one, since the crop events just check themselves and can easily be copy/pasted with the way they are set-up. :-)

Here, I'll try to clarify what's going on with pictures ^^;. Sorry, I'm so awful at explaining things... ;___;



Here's a picture of my placeholder map where I'm working out all the events:

Spoiler for:

The event circled in red is the event I have running right now. The one circled in blue is the event that is used for the "crops". I made its graphic a seedling now so its easier to identify. ;o Once I'm done with that crop event, I'm going to copy and paste it as many times as I want, in each place where the player can grow crops.

Basically, I wanted to take the events of the red circled event and put them in the blue (crop) event. The red event runs parallel process, checks the crop event's variable for "Growth", and then changes the graphic. Here's how it looks:

Spoiler for:

The issue is the part underlined. [1, "Growth"] is telling the branch to check the variable "Growth" on event 1 (the crop event). However, if I were to duplicate the crop event, I would have to re-create what is in the picture, only for 20-30 crops events, and for 20 crop "types" each. It's do-able, but would end up being really complicated and tedious. ;9

This is what I want the event to look like:

Spoiler for:

I didn't have to specify the event number, so this means that it checks whatever event is running this branch. :-) I'd like to see if it's possible, in some way that I may have missed, to have the crop event run that and not need another event entirely. If each crop event runs that, all I could copy + paste the crop event to my heart's content and each event will automatically check itself.



The reasons I failed to have the crop event run the second event page I screenshoted is because the event kept finding ways to erase the pictures I change it to. The first thing I tried was to have the crop run a parallel process event, change its own graphic, and then erase the event. However, the "erase event" feature ended up erasing the event's graphic, too. ;9

The second method was to use a self switch to end the parallel process, but whenever I set it to "self switch" itself out of the event and into an "action button" event instead, it just ended up changing the event graphic to whatever graphic was on the "self switch/action button" event page.

Spoiler for Screenshot:

^Basically, it changed to whatever is in that box. ;_;



So, in summary, I'd like to see if there's another way to have the crop event change its own graphics and keep them changed. I think the only way this could be done is by having a parallel process run every time you enter the map and change them. But the problem is with trying to get the crop events themselves to run the parallel process event without deleting the graphics afterwards, instead of having to use that event I had up near the corner. ;9

Thanks again, guys. Sorry for making things confusing. ;_;
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


*
A-pow 2015
Rep:
Level 81
2014 Best RPG Maker User - GraphicsFor frequently finding and reporting spam and spam bots2013 Most Unsung MemberSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.How can I help you? :Da^2 + b^2 = c^2Secret Santa 2012 ParticipantSilver - GIAW 10Silver - GIAW 9Bronze - GIAW HalloweenGold - Game In A Week VII
Can you specify an event through a variable?
You could make a loop that increases a variable by 1 to go through all the events.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Okay, now I feel bad. ;9 I just want to thank you guys for trying to help me out with this really weird problem. I *think* I just found the solution.

Using Hime's Event Page Conditions, I was able to set the conditions up to match the script variable. I think I can just use a different event page for each crop graphic. Like so:



^ And just have the graphic show up in the graphics box. It may require a LOT of event pages, but hopefully RPG Maker can handle it. B)

So, once again...thank you guys. ;_; I'm sorry to post all this and then be a derp and realize the answer was right in front of me.
« Last Edit: August 22, 2014, 01:19:50 AM by yuyu! »
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Oh that's much simpler, glad it works

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Me too. :) The only downside is needing a TON of event pages, but as long as that doesn't cause any issues, I think it'll be okay... *I hope. Haha :V

*edit*

Well, the max amount of event pages I can use per event is 99, so hopefully I can find a way around that. Gonna have about 22 crops, 2-3 growth stages each, and watered forms of each crop's growth stage. Now I just have to experiment and see if I can downsize the number of pages needed somehow.
« Last Edit: August 22, 2014, 04:52:05 AM by yuyu! »
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Maybe you could make the event page a parallel process and tag on the beginning a graphic change. It should change instantly, but I dunno might get laggy with tons of them on the map

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
I tried to do Parallel Processing, and it dropped my FPS to 10 if I let it continuously run. ;_; Trying to have it run parallel and then end was where I started having all those problems. ;9 This event system hates me...

What I might try to do is have this stack events script running and use a generic graphic for a splash of water, have that stack on the crops as the event that shows the crop "watered". Hopefully, that will cut out half of the events. The "watering" graphic for each one was literally half of it. ;_; Time to see if this works...
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
How about you have a small "loading time" when entering the map, and on each event run the parallel process one time to set the graphic and then change to a standard action button event. Something like:
Code: [Select]
Conditional branch: Graphic Condition
set self switch A
Change graphic
Then just have the event on page 2 be a blank event or however you had it before. This way it would only cause a little lag when you first get on the map and then it would clear up. You could fade the screen black for a few extra frames on the transfer so you can hide the lag.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Oh, wooooow. Woooooooooooow! I-I see what I did now. ;_;

Chaos - That honestly solves the entire problem right there for me. You see, I was setting the self switch to turn "ON" after I changed the graphics. But now that I put them like you have them, before, it changes the graphics of the "self switch A" event. I feel so dumb for making such a rookie mistake, but I can't tell you how relieved I am. ;___;

You're awesome. Thank yoooooou!! ;o;

Out of curiosity, is there any way to affect all self switches on a map at the same time? If not, I can manually change them via event script call or something (I think)! ;o That way, I could just have every self switch on the map turn off "A" upon exiting so the parallel process re-runs every time I enter the map.

Thanks again. You guys really are the best!! :gracie:
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Yes, there is :]
You can put that directly into a script call and it will turn off all self switch A on the map
Code: [Select]
values = ['A', 'B', 'C', 'D']
$game_map.events.values.each do |event|
  $game_self_switches[[$game_map.map_id, event.id, values[0]]] = false
end
Change the "values[0]" to reflect the letters in the array.
0 = A
1 = B
2 = C
3 = D

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee! That's perfect!!

;___; Thank you so much!!
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Lol, no problem

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
I was so excited to finally get this farm system up and running and just realized that this little snippet might just solve even more of my problems (mining and lumber harvesting!) ;o;

Yes, there is :]
You can put that directly into a script call and it will turn off all self switch A on the map
Code: [Select]
values = ['A', 'B', 'C', 'D']
$game_map.events.values.each do |event|
  $game_self_switches[[$game_map.map_id, event.id, values[0]]] = false
end

But I was wondering...is it possible to specify another map in that snippet? :-) Say, if I want to have all of self switch A turned off on map 17 (while on a different map)? I tried a number of things, but couldn't quite get it to work. ;_; The solution is probably really obvious and right under my nose, too. D:

Thanks again for all your help, guys! ;___;
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


**
Rep:
Level 36
Scripter
I think something like this should be work. You only need to replace the value of map_id to select the ID of the map you want to put the self switches to off.

Code: [Select]
    values = ['A', 'B', 'C', 'D']
    map_id = 2
    $temp_map = Game_Map.new
    $temp_map.setup(map_id)
    $temp_map.events.values.each do |event|
      $game_self_switches[[$temp_map.map_id, event.id, values[0]]] = false
    end

EDIT: If you want it we can even make a function inside the Game_Interpreter class so you only need to use a script call for that function in the event.
« Last Edit: August 29, 2014, 02:09:07 PM by Axel Mherkor »

***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
You can do what axel suggests, which is better actually (to have it in the interpreter), but I'll let him show that method :P
Or just change this line
Code: [Select]
$game_self_switches[[$game_map.map_id, event.id, values[0]]] = false
$game_map.map_id is the map id, so just change that part :P

**
Rep:
Level 36
Scripter
$game_map.map_id is the map id, so just change that part :P

It's true that you can put it like the map ID, but changing only that won't work, you need to go through all the events of that map too, is that the reason behind the lines I put. If you want to put it like a game interpreter method the code should be something like this:

Code: [Select]
#==============================================================================
# CHANGE SELF SWITCHES
#==============================================================================
# Instructions:
#------------------------------------------------------------------------------
#    Add this script after the materils section and before the main process
#    section.
#
#    With this you can control the self switches for the event with a script
#    call into the event page. For that you need to write in it one of this
#    functions:
#
#      change_self_switches(value, turn_on)
#        With this function you can update the value of all the self switches
#        of one type in the current map. You need to substitute:
#        -> value   - It should be the name of the switch, 'A', 'B', 'C' and
#                     'D' are the default ones of the RPG Maker, but you can
#                     use any other.
#        -> turn_on - true to turn the self switches on and false to turn them
#                     off.
#
#      change_self_switches(value, turn_on, map_id)
#        With this function you can update the value of all the self switches
#        of one type in the specified map. You need to substitute:
#        -> value   - It should be the name of the switch, 'A', 'B', 'C' and
#                     'D' are the default ones of the RPG Maker, but you can
#                     use any other.
#        -> turn_on - true to turn the self switches on and false to turn them
#                     off.
#        -> map_id  - The number of the map you want to change the self
#                     switches.
#==============================================================================
class Game_Interpreter
  def change_self_switches(value, turn_on, map_id = $game_map.map_id)
    $temp_map = Game_Map.new
    $temp_map.setup(map_id)
    $temp_map.events.values.each do |event|
      $game_self_switches[[$temp_map.map_id, event.id, value]] = turn_on
    end
  end
end


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
$game_map.map_id is the map id, so just change that part :P
It's true that you can put it like the map ID, but changing only that won't work, you need to go through all the events of that map too[...]
Hence the reason for the earlier script
Code: [Select]
values = ['A', 'B', 'C', 'D']
$game_map.events.values.each do |event|
  $game_self_switches[[$game_map.map_id, event.id, values[0]]] = false
end
Cycles through all events and turns off any self switches. Your method just makes it easier because you don't need to copy paste this each time :P

So @yuyu, you would just change $game_map.map_id to the appropriate ID in this case.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Whoa, thanks for all the replies, guys! *__* You all have been a HUGE help! :gracie: It works perfect now!!

Spoiler for:
I couldn't quite get this method to work though:
Code: [Select]
values = ['A', 'B', 'C', 'D']
$game_map.events.values.each do |event|
  $game_self_switches[[17, event.id, values[0]]] = false
end
But I probably goofed somewhere. ;9
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 72
The cloaked schemer
Most Promising Project 2014
Oh my bad, I goofed. If you still wanted to do it from a script call then you need these lines from the script he posted. I kinda forgot that you need to setup the map before doing the loop ._.
Code: [Select]
    values = ['A', 'B', 'C', 'D']
    $temp_map = Game_Map.new
    $temp_map.setup(#map_id)
    $temp_map.events.values.each do |event|
      $game_self_switches[[$temp_map.map_id, event.id, value]] = turn_on
    end

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Ohhhh, okay! ^_^ That makes sense!

Thanks again, guys! ;o; You both solved my issue perfectly! :D
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 70
RMRK Junior
I'll expand on this...

One of the issues with Self Switches is that without scripts, it is difficult to check for a Self Switch condition outside of the executing event.  I'll explain that better.  Event #12 has Self Swtich B set to On, but Event #17 has no way to check or change that!  It really makes games a total mess when you have to use a Global Game Switch for just one Event!  It is issues like this that caused me to write a script to handle these problems.  It is for XP but should work fine on other versions, and should not have any conflicts with other scripts.

Control Self Switches Anywhere

Spoiler for:
Code: [Select]
#==============================================================================
#
#      HERETIC'S CONTROL SELF SWITCHES ANYWHERE
#      Version 1.0
#      Monday, September 9th, 2013
#
#==============================================================================
#
#  The Default Game Engine allows you to change Game Switches from a Move Route
#  but does NOT have anything to allow you to change Self Switches.  This
#  script will allow you to Check and Change ANY Self Switches for Any Event
#  on your Current Map.
#
#    * get_self_switch( Letter, event_id)
#      - Letter is 'A', 'B', 'C', or 'D', WITH Quotes, Upper case doesnt matter
#      - Returns True if Switch is ON
#      - Returns False if Switch is OFF
#    * set_self_switch( Letter, On or Off, event_id)
#      - Letter is 'A', 'B', 'C', or 'D', WITH Quotes, Upper case doesnt matter
#      - Sets Switch Letter to Value (true or false, 'On' and 'Off' okay too)
#
#  The intent of this script is to save you from always having to use
#  Game Switches by allowing you more access to Self Switches.  Too
#  many Game Switches can make your game excessively comples for things
#  that will most likely only relate to Events on One Map.  If you need
#  to check Switches across Game Maps or during Battle, then the use of
#  Game Switches is a better idea.
#
#  NOTE:  The script calls in Event -> Script and Move Route -> Script are
#  quite similar, but not exactly the same.  It may be easiest for you to
#  use this script by calling ALL of the arguments.
#
#  get_self_switch can use TWO Arguments
#  set_self_switch can use THREE Arguments
#
#  If you have any difficulty with the Script Calls, just use all arguments
#  and that will usually solve your problems.  I tried to set up this script
#  to provide lots of error messages that clearly explain what went wrong
#  should something go wrong in your script call.
#
#  NOTE: I allowed for the usage of get_self_switch inside of Set Move Route
#  because you can use a Ternary Operator for Conditional Move Routes.  It is
#  very unlikely that you'll ever need to use get_self_switch inside of
#  Set Move Route -> Script.
#
#  NOTE: You can set a Self Switch for ANY Event on your Game Map, even from
#  setting a Player Move Route -> Script.  When using Player, you MUST call
#  for an Event ID as the Game Player has no Self Switches.  This may be
#  much easier than jumping in and out of Set Move Route when trying to
#  synchronize movements.
#
#  Installation
#
#  Put anywhere between the Default Scripts and Main.  These are all unique
#  definitions so this script should be perfectly compatible with ALL other
#  scripts in existence.
#
#  ---  Limitations  ---
#
#  You cant use during either Battle or Different Maps.
#
#  ---  Usage  ---
#
#  You can use anywhere you can make a Script Call, except in Battle.
#
#  For Conditional Branching, in Events Page 1, click on Conditional Branch.
#  Then in Page 4 of the Conditional Branch, go to Script.
#  In Script, enter "get_self_switch(Letter, event_id) == true / false"
#  -  Dont use Quotes on the whole statement
#  -  Dont use the word IF
#  -  (Letter is 'A', 'B', 'C', or 'D') WITH Quotes in the Script Call.
#  -  Event ID does NOT have Quotes.
#
#  Dont forget you CAN PRINT anywhere you can enter a Script Call also.
#  print get_self_switch(Letter, event_id)
#
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Set Self Switch(ch, value, id)
  #        ch : A, B, C, or D
  #     value : true, false, 'On', 'Off', 1, or 0
  #       id  : Event ID
  #
  #   - Change a Self Switch from a Move Route Event
  #-------------------------------------------------------------------------- 
  def set_self_switch(ch, value, id = @id)
    # if Player Move Route and id is not Specified
    if id == 0 and $DEBUG
      # Print Error
      print "When using set_self_switch for Player Move Route, you need to\n",
            "specify an Event ID because the Game Player does not\n",
            "have any Self Switches"
    end

    # Valid Values
    value_valid = [true, false, 0, 1, 'on','off']
    if value.is_a?(String)
      value = true if value.to_s.downcase == 'on'
      value = false if value.to_s.downcase == 'off'
    elsif value.is_a?(Integer)
      value = true if value == 1
      value = false if value == 0
    end
   # If we have A, B, C, or D, and the Event exists   
    if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
       (value == true or value == false) and $game_map.events[id]
      # If event ID is valid
      if @id > 0 and
        # Make Upper Case for Key
        ch = ch.to_s.upcase
        # Make a self switch key
        key = [$game_map.map_id, id, ch]
        # Change self switches
        $game_self_switches[key] = value
      end
      # Refresh map
      $game_map.need_refresh = true
      # Continue
      return true
    else
      if $DEBUG
        print "Warning: set_self_switch expects Two Arguments\n",
              "The First Argument should be the letter A, B, C, or D\n",
              "The Second Argument should be either True or False.\n",
              "(On or Off is acceptable too.  Just need you",
              "to say what you want to set it to.)\n\n",
              "Example: set_self_switch('A',true)\n\n",
              "Example 2: set_self_switch('A','On')\n\n",
              "There is an Optional 3rd Argument for",
              "specifying an Event ID\n\n",
              "Example 2: set_self_switch('B',false, 32)\n\n",
              "This Script call to get_self_switch was made\n",
              "from MOVE ROUTE => SCRIPT\n\n",
              "set_self_switch in MOVE ROUTES => SCRIPT expect TWO Arguments, THIRD Optional\n",
              "set_self_switch in EVENT => SCRIPT expects THREE Arguments\n\n",
              "Your Script: Move Route -> Script set_self_switch('",ch,"','",value,"','",id,"')"
        if not $game_map.events[id]
          print "The Event ID: ", id, " you specified\n",
                "doesn't exist on this map"
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Get Self Switch(ch, id)
  #        ch : A, B, C, or D
  #       id  : Event ID
  #
  #   - Returns True if a Switch is ON, False if Switch is OFF
  #   - This is usually only good with Ternary Operator but I included it anyway
  #     Example:  @direction = (get_self_switch('A',15) ? 8 : 2
  #-------------------------------------------------------------------------- 
  def get_self_switch(ch, id = @id)
    # if Player Move Route and id is not Specified
    if id == 0 and $DEBUG
      # Print Error
      print "When using get_self_switch for Player Set Move Route, you need to\n",
            "specify an Event ID because the Game Player does not\n",
            "have any Self Switches\n\n",
            "Calling in Player with no ID argument causes\n",
            "the ID to be set to 0"
    end   
    # If we have A, B, C, or D, and the Event exists
    if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
       id and $game_map.events[id]
      # Make a Key
      key = [$game_map.map_id, id, ch.upcase]
      return $game_self_switches[key]
    else
      if $DEBUG
        print "Warning: get_self_switch expects Two Arguments\n",
              "The First Argument should be the Letter of\n",
              " the Self Switch you are Checking, A, B, C, or D\n",       
              "The Second Argument should be the Event's ID\n",

              "Example: get_self_switch('B', 23)\n\n",
              "This Script call to get_self_switch was made\n",
              "from MOVE ROUTE => SCRIPT\n\n",
              "Your Script: Move Route -> Script get_self_switch('",ch,"','",id,"')"           
        if not $game_map.events[id]
          print "The Event ID: ", id, " you specified\n",
                "doesn't exist on this map"
        end
      end
    end
  end
end

class Interpreter
  #--------------------------------------------------------------------------
  # * Get Self Switch(ch, id)
  #        ch : A, B, C, or D
  #       id  : Event ID (Default to self.id)
  #
  #   - Returns True if a Switch is ON, False if Switch is OFF
  #   - This is NOT called from Move Route - Script
  #-------------------------------------------------------------------------- 
  def get_self_switch(ch, id = nil)
    # If we have A, B, C, or D, and the Event exists   
    if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
       id and $game_map.events[id]
      # Make a Key
      key = [$game_map.map_id, id, ch.upcase]
      return $game_self_switches[key]
    else
      if $DEBUG
        print "Warning: get_self_switch expects Two Arguments\n",
              "The First Argument should be the Letter of\n",
              " the Self Switch you are Checking, A, B, C, or D\n",       
              "The Second Argument should be the Event's ID\n",
              "Example: get_self_switch('B', 23)\n\n",
              "Note: The call that generated this error",
              "was NOT called from a Move Route\n ",
              "just an Event Script\n\n",
              "Your Script: Event -> Script get_self_switch('",ch,"','",id,"')"
        if id.nil?
          print "The Event ID: ", id, " isn't set in your script call"
        elsif not $game_map.events[id]
          print "The Event ID: ", id, " doesn't exist on this map"
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Set Self Switch(ch, value, id)
  #        ch : A, B, C, or D
  #     value : true, false, 'On', 'Off', 1, or 0
  #       id  : Event ID (default self.id)
  #
  #   - Change a Self Switch for any Event from another Event -> Script
  #   - Use this ONLY to change a Self Switch for another Event.  The
  #     game engine already has a button for changing Self Switches. 
  #   - This is NOT called from Move Route - Script
  #-------------------------------------------------------------------------- 
  def set_self_switch(ch, value, id=nil)
    # Valid Values
    value_valid = [true, false, 0, 1, 'on','off']
    if value.is_a?(String)
      value = true if value.to_s.downcase == 'on'
      value = false if value.to_s.downcase == 'off'
    elsif value.is_a?(Integer)
      value = true if value == 1
      value = false if value == 0
    end
    if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
       (value == true or value == false) and id and $game_map.events[id]
      # If event ID is valid
      if id > 0 and
        # Make Upper Case for Key
        ch = ch.to_s.upcase
        # Make a self switch key
        key = [$game_map.map_id, id, ch]
        # Change self switches
        $game_self_switches[key] = value
      end
      # Refresh map
      $game_map.need_refresh = true
      # Continue
      return true
    else
      if $DEBUG
        print "Warning: set_self_switch expects THREE Arguments\n",
              "The First Argument should be the letter A, B, C, or D\n",
              "The Second Argument should be either True or False\n",
              "The 3rd Argument is used to specify an Event ID\n\n",
              "Example: set_self_switch('B','Off', 32)\n\n",
              "Note: The call that generated this error ",
              "was NOT called from a Move Route\n",
              "just an Event Script\n\n",
              "set_self_switch in MOVE ROUTES => SCRIPT expect TWO Arguments, THIRD Optional\n",
              "set_self_switch in EVENT => SCRIPT expects THREE Arguments\n\n",
              "Your Script: Event -> Script set_self_switch('",ch,"','",value,"','",id,"')"             
             
        if id.nil?
          print "The Event ID: ", id, " isn't set in your script call"
        elsif not $game_map.events[id]
          print "The Event ID: ", id, " doesn't exist on this map"
        end             
      end
    end
  end   
end

There are two Script calls:

Code: [Select]
get_self_switch(Letter, Event ID)
set_self_switch(Letter, State, Event ID)

The calls are pretty easy.  Letter is 'A', 'B', 'C', or 'D'.  State is 'On' or 'Off'.  Event ID is the number.

Examples:

Code: [Select]
# Sets Self Switch A to the On state for Event 12
set_self_switch('A', 'On', 12)
# Returns what value a Self Switch is set to for Event 17
get_self_switch('A', 17)

The 'get' version can be used in Conditional Branches.  It returns true if on or false if off.  Also, leave the word "if" out of your script call in Conditional Branches. 

Code: [Select]
if get_self_switch('A', 12) == true / false
if get_self_switch('D', 5)  # this checks for true

You can check if a Self Switch is Off by using the word 'not'

Code: [Select]
if not get_self_switch('C', 19) == false
if not get_self_switch('B', 6) # this checks if false

In the Conditional Branches -> Scripts box, you can also check for Multiple Switches.  This is more of a scripting thing, but it will evaluate everything inside the parenthesis.  For this example, Self Switch A is used for both events, Event 1 has Self Switch A set to On and Event 2 is set to Off.

Code: [Select]
if (get_self_switch('A', 1) AND get_self_switch('A', 2) )

Both Self Switches will need to be On for that condition to eval to true.  Both will be required because of the word AND in that statement.  Because Self Switch A for Event 2 is set to Off, this will NOT evaluate to true.

You can also use an OR statement.

Code: [Select]
if (get_self_switch('A', 1) OR get_self_switch('A', 2) )

In that example, if EITHER of the Self Switches is On, the script will evaluate to true.

You can also use an XOR statement.  Briefly, an XOR statement means one or the other, but not both.

Code: [Select]
if (get_self_switch('A', 1) XOR get_self_switch('A', 2) )

Operands:

&& is the Operand for AND
|| is the Operand for OR
^ is the Operand for XOR

Loops:

You can use the Script Box to do a Loop for ALL events quite easily.

Code: [Select]
for event_id in $game_map.events
  set_self_switch('A', 'On', event_id)
end

There is another way to do this.  The above code will turn Self Switch A to On for ALL EVENTS on a map.  The code $game_map.events is what contains all of the Event ID's for your current map.  But this list is not required; its just a set of numbers.  You could also do it just like this:

Code: [Select]
events = [12,14,27,13,5,112,4]
for event_id in events
  set_self_switch('B', 'Off', event_id)
end

That code is also simple enough that it will fit in a Script Container.  It just creates a temporary variable called events, which is an array of numbers that can be iterated through quickly.  So performance of running this script wont be an issue. 

Another thing to note is that I very strongly recommend that you do not use either instance or global variables.  That is to say, dont put either an @ or a $ symbol in front of the variable names.  Thus, @event_id = [1,2,3,4,6], thats bad juju.  So is "for $id in @event_ids".  Those variables stick around in either the Interpreter or Event and can be a game killing bug. 

Limitations and Compatability:

Game_guy wrote a deceptively titled script called More Self Switches.  His script allows you to use whatever Switch Name you want.  So now you can have Self Switch E or Self Switch F.  You arent limited to Single Letters and can use any descriptor you want for your Self Switches.  It allows for Self Switch Taco or Self Swtich Defeated.  The deceptive part of the Script Name is that it also allows each of those Self Switches to be treated as a Page Condition.  In an Event Comment at the top of the Event Page, put in a Comment that reads "switch:foo".  Of course, without the quotes, and "foo" being an Self Switch.  Self Switch Foo.  I think his script really should have been titled "More Self Switches and Page Conditions" to clearly explain its nature.  But that is just a minor nitpick as it is the functionality that really shines.

His script is compatible with the one I put up earlier.  The Limitation that I mentioned is my script only checks for A, B, C, or D, so customized Switch Names dont work.  I might expand this if it is needed. 

Other things that will cause you problems would be that when doing Script Calls and NOT in a Comment Box, you'll need to use quotes for Names and States.  set_self_switch('A', 'On', 35), those  characters do need to be there.  In a Comment Box, the Switch Names do not need to be there.  switch:foo  No quotes. 

The last limitation in this script is that it does NOT allow for checking Self Switches across different Maps.  Each map will have Event 1, 2 so on and so forth.  I havent put anything in to check Event 1 on a different map. 

---

Self Switches are a hash key / value pair.  The script I posted above is superfluous if you know how to access these directly, and it does allow access to any Switch Names as well as other maps.  Scripters typically know how to access these, but the new user wont, but it is possible.  The script calls that run inside events has enough room that you can access these without my script.  I just tried to make it easier for everyone to do.
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Woah that's pretty cool O.O Thank you for elaborating, Heretic! ^_^

You guys posted a lot of great content in this thread! :D So much more that can be done with Self Switches! ;___;
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]