11-12-2009, 05:31 AM
(This post was last modified: 09-02-2024, 09:50 PM by DerVVulfman.)
Group Variables
Version: 1.1
Version: 1.1
Introduction
This small code allows game creators to set, add, subtract, multiply, etc. values from variables.
Features
- Adjust the values of multiple variables.
Screenshots
No screencaps.
Demo
No demo.
Script
Code:
=begin
????????????????????????????????????????????????????????????????????????????????
? Group Variables by PK8 v1.1, November 11th, 2009. ?
? http://rmvxp.com ?
????????????????????????????????????????????????????????????????????????????????
? ? Table of Contents ?
? ?? Author's Notes - Line 13,14 ?
? ?? Introduction & Description - Line 16?18 ?
? ?? Features - Line 20,21 ?
? ?? How to Use - Line 23?48 ?
? ?? Changelog - Line 50?52 ?
????????????????????????????????????????????????????????????????????????????????
? ? Author's Notes ?
? Boredom + running out of ideas = this script. :P ?
????????????????????????????????????????????????????????????????????????????????
? ? Introduction & Description ?
? This small code allows game creators to set, add, subtract, multiply, etc. ?
? values from variables. ?
????????????????????????????????????????????????????????????????????????????????
? ? Features ?
? ? Adjust the values of multiple variables. ?
????????????????????????????????????????????????????????????????????????????????
? ? How to Use ?
? Call script: group_variable(oper, value, any number of variables) ?
? oper: ?
? 0, 'set', '=': Sets value of variables. ?
? 1, 'add', '+': Adds value to variables. ?
? 2, 'sub', '-': Subtracts value from variables. ?
? 3, 'mul', '*': Multiplies variables by value. ?
? 4, 'div', '/': Divides variables by value. ?
? 5, 'mod', '%': Divides variables by value, returns remainder (I think). ?
? ?
? Example: ?
? group_variable('set', 20, 1..8,10,12) ?
? The above script call sets the values of variables 1-8, 10 & 12 to 20. ?
? ?
? group_variable('add', 10, 3,7,11) ?
? The above script call adds 10 to the values of variables 3, 7 and 11. ?
? ?
? group_variable('sub', 5, 2,9,20) ?
? The above script call subtracts 5 from the values of variables 2,9 & 20?
? ?
? group_variable('mul', 2, 1..3,5) ?
? The above script call multiplies the values of variables 1-3 & 5 by 2. ?
? ?
? Also: You could use ranges in the arguments. Here's an example: * ?
? group_variable('set', 2, 1..10, 18, 12..15) ?
? The above call will set the values of variables 1-10, 18 and 12-15 to 2. ?
????????????????????????????????????????????????????????????????????????????????
? ? Changelog ?
? v1.1 (Nov. 12th, 2009): Added group_variables call for anyone who'd prefer ?
? using that instead of group_variable. ?
????????????????????????????????????????????????????????????????????????????????
=end
#==============================================================================
# IMPORTANT! RMVX users, set this to false!
#==============================================================================
class PK8
Group_Variable_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::Group_Variable_RMXP == true
class Interpreter
def group_variable(oper, value, *variables)
variables.each_index { | index |
# Pushes everything in the range to the variable array.
if variables[index].is_a?(Range) == true
variables[index].each {| n | variables.push(n) }
variables[index] = nil
end
}
variables.compact!
# This is where it does it's business.
case oper
when 0, 'set', 'substitute', 'is', '='
variables.each { | i | $game_variables[i] = value }
when 1, 'add', 'addition', 'plus', '+'
variables.each { | i | $game_variables[i] += value }
when 2, 'sub', 'subtract', 'subtraction', 'minus', '-'
variables.each { | i | $game_variables[i] -= value }
when 3, 'mul', 'multiply', 'multiplication', 'times', 'x', '*'
variables.each { | i | $game_variables[i] *= value }
when 4, 'div', 'divide', 'division', 'divided by', '/'
variables.each { | i | $game_variables[i] /= value }
when 5, 'mod', 'modulo', '%'
variables.each { | i | $game_variables[i] %= value }
end
return
end
# Alternate Call.
def group_variables(oper, value, *variables)
group_variable(oper, value, *variables)
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::Group_Variable_RMXP == false
class Game_Interpreter
def group_variable(oper, value, *variables)
variables.each_index { | index |
# Pushes everything in the range to the variable array.
if variables[index].is_a?(Range) == true
variables[index].each {| n | variables.push(n) }
variables[index] = nil
end
}
variables.compact!
# This is where it does it's business.
case oper
when 0, 'set', 'substitute', 'is', '='
variables.each { | i | $game_variables[i] = value }
when 1, 'add', 'addition', 'plus', '+'
variables.each { | i | $game_variables[i] += value }
when 2, 'sub', 'subtract', 'subtraction', 'minus', '-'
variables.each { | i | $game_variables[i] -= value }
when 3, 'mul', 'multiply', 'multiplication', 'times', 'x', '*'
variables.each { | i | $game_variables[i] *= value }
when 4, 'div', 'divide', 'division', 'divided by', '/'
variables.each { | i | $game_variables[i] /= value }
when 5, 'mod', 'modulo', '%'
variables.each { | i | $game_variables[i] %= value }
end
return
end
# Alternate Call.
def group_variables(oper, value, *variables)
group_variable(oper, value, *variables)
end
end
end
Instructions
Instructions are in the script.
FAQ
If you've any questions or if you're feeling pretty confused, feel free to post a question. :P
Compatibility
It should have no problem when it comes to compatibility.
Credits and Thanks
No credits.
Author's Notes
Boredom + Running out of ideas = this script.
Terms and Conditions
Credit me. :3