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.
Switch Operations

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Switch Operations
Version: 1.0
Author: modern algebra
Date: March 4, 2010

Version History


  • <Version 1.0> 03.04.2010 - Original Release

Description


This script allows you to very easily set the value of an ingame switch to check a number of particular values that would normally be accessible only through knowledge of Ruby syntax and RGSS2 methods. It is also easy to add new checks to this interface and requires very little scripting knowledge.

Features

By default, you can set a switch to check if:
  • the current playthrough is a Play Test
  • the player is in a given area
  • the player is in a vehicle
  • the player is on a given square
  • any map event is on a given square
  • the self-switch of another event on the same map is ON
  • any type of weather is currently active
  • the message window is open

Instructions

Place the script in its own slot in the Materials section of the Script Editor, below the default scripts but still above Main.

See the header of the script for instructions on using the script.

Script


Code: [Select]
#==============================================================================
#    Switch Operations
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: March 4, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to very easily set the value of an ingame switch to
#   check a number of particular values that would normally be accessible only
#   through knowledge of Ruby syntax and RGSS2 methods. It is also easy to add
#   new checks that would be available through the same framework.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    The script is very easy to use; all you need to do is put any of the
#   following codes in a call script. In all of the following, switch_id refers
#   to the ID of the switch that you are setting equal to the check. All other
#   arguments, x, y, or z, refer to whatever is specified in the description
#   line.
#
#    Check if Player is in the Area with ID x:
#      set_switch_to (:in_area, switch_id, x)
#      EXAMPLE: set_switch_to (:in_area, 2, 1)
#        Checks if player is within Area 1 and saves it to Switch 2
#    Check if player is in any vehicle:
#      set_switch_to (:in_vehicle, switch_id)
#      EXAMPLE: set_switch_to (:in_vehicle, 1)
#        Checks if player is in a vehicle and saves it to Switch 1
#    Check if this is a play test:
#      set_switch_to (:playtest, switch_id)
#      EXAMPLE: set_switch_to (:playtest, 7)
#        Checks if this is a play test and saves it to Switch 7
#    Check if the self switch with label y is ON for the event with ID x
#      set_switch_to (:event_selfswitch, switch_id, x, y)
#      EXAMPLE: set_switch_to (:event_selfswitch, 5, 3, "C")
#        Checks if self switch C of the event with ID 3 and saves to Switch 5
#    Check if event with ID z is on the square with coordinates x & y
#      set_switch_to (:event_xy, switch_id, z, x, y)
#      EXAMPLE: set_switch_to (:event_xy, 13, 8, 12, 18)
#        Checks if Event 8 is at (12, 18) and saves result to Switch 13
#    Check if player is on the square with coordinates x & y
#      set_switch_to (:player_xy, switch_id, x, y)
#      EXAMPLE: set_switch_to (:player_xy, 1, 11, 13)
#        Checks if Player is at (11, 13) and saves result to Switch 1
#    Check if it is raining
#      set_switch_to (:raining, switch_id)
#      EXAMPLE: set_switch_to (:raining, 12)
#        Checks if the weather is set to rain and saves result to Switch 12
#    Check if it is storming
#      set_switch_to (:storming, switch_id)
#      EXAMPLE: set_switch_to (:storming, 9)
#        Checks if the weather is set to storm and saves result to Switch 9
#    Check if it is snowing
#      set_switch_to (:snowing, switch_id)
#      EXAMPLE: set_switch_to (:snowing, 2)
#        Checks if the weather is set to snow and saves result to Switch 2
#    Check if the message window is currently visible
#      set_switch_to (:message_open, switch_id)
#      EXAMPLE: set_switch_to (:message_open, 5)
#        Checks if the message window is visible and saves result to Switch 5
#    Set to opposite of other switch (or itself)
#      set_switch_to (:toggle, switch_id, switch2_id)
#      EXAMPLE: set_switch_to (:toggle, 1, 2)
#        Sets switch 1 to the opposite of switch 2.
#
#  It is also very easy to include other checks and assign them to switches
# through this interface, though it requires some knowledge of syntax and RGSS2
# methods. It is done below in the SOA_OPERATIONS hash, which should not
# otherwise be modified. If you wish to have other booleans accessible through
# this script but do not know the syntax yourself, please go to RMRK.net and I
# will do my best to assist you and tell you what you need to do and where.
#==============================================================================

SOA_OPERATIONS = {
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  #  This areas should not be touched unless you know what you are doing. In
  # order to add new codes, it simply needs to be of the form:
  #
  #    :symbol => "expression",
  #
  #  where the expression will evaluate to either true or false. If you want to
  # include other arguments, then put <x> where you want those arguments
  # inserted, where x is an integer that represents in what order the arguments
  # are placed. <1> will be replaced with the first additional argument, <2>
  # will be replaced with the second additional argument, etc... For examples,
  # see the default ones that are already set up. Keep in mind that a comma is
  # necessary after every new command except the last one.
  #
  #  If you don't know the correct methods to call for the function you want,
  # feel free to request aid in this script's topic at RMRK.net.
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # set_switch_to (:in_area, switch_id, area_id)
  :in_area => "$game_player.in_area? ($data_areas[<1>])",
  # set_switch_to (:in_vehicle, switch_id)
  :in_vehicle => "$game_player.in_vehicle?",
  # set_switch_to (:playtest, switch_id)
  :playtest => "$TEST",
  # set_switch_to (:event_selfswitch, switch_id, event_id, self_switch_label)
  :event_selfswitch => "$game_self_switches[[$game_map.map_id, <1>, <2>]]",
  # set_switch_to (:event_xy, switch_id, event_id, dest_x, dest_y)
  :event_xy => "$game_map.events[<1>].x == <2> && $game_map.events[<1>].y == <3>",
  # set_switch_to (:player_xy, switch_id, dest_x, dest_y)
  :player_xy => "$game_player.x == <1> && $game_player.y == <2>",
  # set_switch_to (:raining, switch_id)
  :raining => "$game_map.screen.weather_type == 1",
  # set_switch_to (:storming, switch_id)
  :storming => "$game_map.screen.weather_type == 2",
  # set_switch_to (:snowing, switch_id)
  :snowing => "$game_map.screen.weather_type == 3",
  # set_switch_to (:message_open, switch_id)
  :message_open => "$game_message.visible",
  # set_switch_to (:toggle, switch_id, switch2_id)
  :toggle => "!$game_switches[<1>]"
}
SOA_OPERATIONS.default = "false"

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - set_switch_to
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Switch To
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def set_switch_to (symbol, switch_id, *args)
    operation = SOA_OPERATIONS[symbol].dup
    for i in 0...args.size
      operation.gsub! (/<#{(i + 1).to_s}>/) { args[i].is_a? (String) ? "\"#{args[i]}\"" : args[i].to_s }
    end
    eval ("$game_switches[#{switch_id}] = (#{operation})")
  end
end

Credit


  • modern algebra

Support


Please post in this topic for support. Do not PM me. I will fix any bugs you encounter, and I will gladly help you if you want to add any new boolean checks to the script.

Known Compatibility Issues

I don't forsee any compatibility issues.

Demo


I don't think a demo is necessary. Feel free to request one if you disagree.

Author's Notes


While the built-in options are sparse, I specifically made this script so that it would be very easy to add new checks with a minimum of scripting knowledge. If there are any boolean values in scripts that you want to be able to set to a switch in the interface provided by this script, just tell me what it is and I will write it up for you :)


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
« Last Edit: May 16, 2010, 11:26:41 PM by modern algebra »

**
Rep: +0/-0Level 84
VERY useful

***
Rep:
Level 75
What the...?
M_A

So, When you say "saves it to switch x) you are implying that it turns switch on if boolean is true, off if boolean is false.  Is that correct?