Variable Swap [Snippet]
#1
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.
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   VARIABLE ENEMY HP & SP DerVVulfman 0 830 06-14-2024, 07:18 PM
Last Post: DerVVulfman
   Name Game Switch & Variable XP kyonides 0 1,088 06-27-2023, 09:17 PM
Last Post: kyonides
   Weapons Swap XP kyonides 1 1,557 01-15-2023, 04:56 AM
Last Post: kyonides
   Variable Extraction Generator DerVVulfman 0 3,123 07-20-2020, 06:58 PM
Last Post: DerVVulfman
   Tileset Swap ccoa 4 11,675 04-15-2014, 04:18 AM
Last Post: DerVVulfman
   Variable-Based Battle Themes v1.1 PK8 1 7,251 11-27-2009, 07:29 PM
Last Post: explocion200
   Switch Swap [Snippet] PK8 0 4,661 11-09-2009, 07:07 AM
Last Post: PK8
   Variable-Based Battle Victory MEs PK8 4 8,151 09-29-2009, 12:58 PM
Last Post: Alpha-Mad
   Global Variable Standard Check Yeyinde 0 4,587 12-07-2008, 12:03 PM
Last Post: Yeyinde
   Variable Image Menu Mac 0 5,116 03-08-2008, 01:09 AM
Last Post: Mac



Users browsing this thread: 1 Guest(s)