Save-Point
[split] Variable Swap [Snippet] - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker VX/VXAce (RGSS2/3) Engines (https://www.save-point.org/forum-117.html)
+---- Thread: [split] Variable Swap [Snippet] (/thread-9065.html)



[split] Variable Swap [Snippet] - PK8 - 11-15-2009

Variable Swap Snippet

Introduction
This snippet swaps the values of two game variable you specify in a command.

Features
  • Swaps values of Game Variables via command.

Screenshots
No screenshot.

Demo
No demo.

Script
Code:
=begin
????????????????????????????????????????????????????????????????????????????????
? Variable Swap Snippet by PK8, November 9th, 2009.                            ?
? http://rmvxp.com                                                             ?
????????????????????????????????????????????????????????????????????????????????
? ? Table of Contents                                                          ?
? ?? Author's Notes                - Line 12,13                                ?
? ?? Introduction & Description    - Line 15,16                                ?
? ?? Features                      - Line 18,19                                ?
? ?? How to Use                    - Line 21?29                                ?
????????????????????????????????????????????????????????????????????????????????
? ? Author's Notes                                                             ?
? Boredom + running out of ideas = this.                                       ?
????????????????????????????????????????????????????????????????????????????????
? ? Introduction & Description                                                 ?
? This snippet swaps the values of two variables you specify in a command.     ?
????????????????????????????????????????????????????????????????????????????????
? ? Features                                                                   ?
? ? Swap values of two variables with a script call.                           ?
????????????????????????????????????????????????????????????????????????????????
? ? How to Use                                                                 ?
?   Call script: variable_swap(from, to)                                       ?
?     from: Original variable. | to: Variable it's swapping with.              ?
?                                                                              ?
?   Example: Variable ID 1 = 45, Variable ID 5 = 90.                           ?
?       call: variable_swap(1, 5)                                              ?
?     The values of the two variables would swap, which means, going back to   ?
?     the example above, Variable ID 1 would equal 90 and Variable ID 5 would  ?
?     equal 45.                                                                ?
????????????????????????????????????????????????????????????????????????????????
=end

#==============================================================================
# IMPORTANT! RMVX users, set this to false!
#==============================================================================
class PK8
  Variable_Swap_RMXP = true # true if using RMXP, false if using RMVX.
end

#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

if PK8::Variable_Swap_RMXP == true
  class Interpreter
    def variable_swap(from, to)
      fromtemp = $game_variables[from]
      totemp = $game_variables[to]
      $game_variables[from] = totemp
      $game_variables[to] = fromtemp
      return
    end
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

if PK8::Variable_Swap_RMXP == false
  class Game_Interpreter
    def variable_swap(from, to)
      fromtemp = $game_variables[from]
      totemp = $game_variables[to]
      $game_variables[from] = totemp
      $game_variables[to] = fromtemp
      return
    end
  end
end

Instructions
If you're using RMVX, set "Variable_Swap_RMXP" to false. To use it, just call script:
Code:
variable_swap(from, to)

FAQ
Awaiting question.

Compatibility
I'm sure it's compatible.

Credits and Thanks
No thanks. :P

Author's Notes
Boredom + running out of ideas = this script.

Terms and Conditions
Credit's not necessary.