[rmxp] pk8's self variable script and parallel process

Started by Karltheking4, September 25, 2010, 12:21:00 am

Previous topic - Next topic

Karltheking4

September 25, 2010, 12:21:00 am Last Edit: September 25, 2010, 03:51:34 am by Blizzard
pk8's self variable script (below) is a really awesome script, but I can't figure out what this odd problem is.
It won't work in parallel process map events, if you try to script it, it gives you an error on line 127. about not understand '[]''s

Any ideas???

PLease help!!!

pks self variable script: ShowHide

=begin
═══════════════════════════════════════════════════════════════════════════════╗ ​​
║ PK8's Self Variables ║
║ Version 1.0 ║
║ by PK8 ║
║ 9/16/09 ║
║ http://rmvxp.com ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​​
║ ■ Table of Contents ║
║ ├─ Author's Notes - Line 18─21 ║
║ ├─ Introduction & Description - Line 23─29 ║
║ ├─ Features - Line 31─33 ║
║ ├─ How to Use - Line 35─59 ║
║ ├─ This aliases the following... - Line 61─64 ║
║ ├─ Thanks - Line 66─71 ║
║ └─ Changelog - Line 73,74 ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​
║ ■ Author's Notes ║
║ Lowell/Adalwulf mentioned creating a "Personal Variables" system which filled║
║ my head in with ideas about variables and switches. One of these ideas being ║
║ self variables. ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​​
║ ■ Introduction & Description ║
║ This script is pretty similar to that of the built in feature: Self Switches.║
║ For those not familiar with Self Switches, Self Switches pretty much pertain ║
║ to a specific event. Example: Treasure Chests. ║
║ ║
║ Self Variables allows users to set certain variables pertaining to a specific║
║ event. Examples include: An event's feelings towards you. ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​​
║ ■ Features ║
║ ─ Set self variables of an event via call script. (How to use is below) ║
║ ─ Get self variables of an event via call script. (How to use is below) ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​
║ ■ How to Use ║
║ ║
║ ● Setting up a self variable: ║
║ To set a self variable for an event, you'll need to call this script on a ║
║ map event: ║
║ self_variable(id, value, oper) ║
║ id: Self Variable Identification. Example: 'feeling' ║
║ value: Give it a value. ║
║ oper: 0: Set, 1: Add, 2: Sub, 3: Mul, 4: Div, 5: Mod ║
║ ║
║ ● Getting a self variable: ║
║ To get a self variable for an event, you can call this script. ║
║ self_variable(id) ║
║ id: Self Variable Identification. ║
║ ║
║ ● Using self variables in evented if conditions. ║
║ You're probably wondering how, right? Alright. To do this, go to the ║
║ conditional branch event command, click on the fourth tab, select Script ║
║ and type either of these in the input form: ║
║ self_variable(id) == value <- Equal to. ║
║ self_variable(id) >= value <- Greater than or Equal to. ║
║ self_variable(id) <= value <- Less than or Equal to. ║
║ self_variable(id) > value <- Greater than. ║
║ self_variable(id) < value <- Less than. ║
║ self_variable(id) != value <- Not Equal to. ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​
║ ■ This aliases the following... ║
║ command_new_game - Scene_Title ║
║ write_save_data - Scene_Save < Scene_File ║
║ read_save_data - Scene_Load < Scene_File ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​
║ ■ Thanks ║
║ Lowell: He mentioned creating a personal variables system for his project ║
║ (I think), which made me catch "the scripting bug". ║
║ Decibel: Wanted some way to get self variables into messages but I couldn't ║
║ do it. Someone, help! ║
║ Kain Nobel: He helped me with making this an RMXP script. ║
╟──────────────────────────────────────────────────────────────────────────────╢ ​
║ ■ Changelog ║
║ Version 1.0 - 9/16/09: Initial Release ║
╚══════════════════════════════════════════════════════════════════════════════╝ ​​
=end

#==============================================================================
# ** Game_SelfVariables
#------------------------------------------------------------------------------
# This class handles self variables. It's a wrapper for the built-in class
# "Hash." The instance of this class is referenced by $game_self_variables.
#==============================================================================

class Game_SelfVariables
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = {}
end
#--------------------------------------------------------------------------
# * Get Self Switch
# key : key
#--------------------------------------------------------------------------
def [](key)
if @data[key] == nil
return 0
else
return @data[key]
end
end
#--------------------------------------------------------------------------
# * Set Self Switch
# key : key
# value : key's value
#--------------------------------------------------------------------------
def []=(key, value)
@data[key] = value
end
end

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

class Interpreter
def self_variable(id, value = nil, oper = nil)
if @event_id > 0
key = [@map_id, @event_id, id]
if value != nil
case oper
when nil, 0, 'equal', 'set', '=' # Setting
$game_self_variables[key] = value
when 1, 'add', '+' # Adding
$game_self_variables[key] += value
when 2, 'sub', 'subtract', '-' # Subtracting
$game_self_variables[key] -= value
when 3, 'mul', 'multiply', 'x', '*' # Multiplying
$game_self_variables[key] *= value
when 4, 'div', 'divide', '/' # Dividing
$game_self_variables[key] /= value if value != 0
when 5, 'mod', 'modular', '%' # Modulating
$game_self_variables[key] %= value if value != 0
end
else
return $game_self_variables[key]
end
if value != nil
$game_map.need_refresh = true
return true
end
end
end
end

#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================

class Scene_Title
alias pk8_self_variables_command_new_game :command_new_game
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
def command_new_game
pk8_self_variables_command_new_game
$game_self_variables = Game_SelfVariables.new
end
end

#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
# This class performs save screen processing.
#==============================================================================

class Scene_Save < Scene_File
alias pk8_self_variables_write_save_data :write_save_data
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
pk8_self_variables_write_save_data(file)
Marshal.dump($game_self_variables, file)
end
end

#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
# This class performs load screen processing.
#==============================================================================

class Scene_Load < Scene_File
alias pk8_self_variables_read_save_data :read_save_data
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
def read_save_data(file)
pk8_self_variables_read_save_data(file)
$game_self_variables = Marshal.load(file)
end
end

Blizzard

Make sure you are starting a new game rather than loading a previously saved game from when you didn't have the script yet.

Also, in future put your code in spoiler tags. Otherwise it can get broken.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Karltheking4

Creating an entirely new project with just that script, 1 parallel process map event with
self_variable(1, 1, 0)
print self_variable(1)
gives you the same error!!! :'(

The odd thing is though, it works fine if it's an autorun event, but unfortunetly, that's not needed!!!

also, woops! sorry! :^_^':

Blizzard

Are you sure that you are using the right key here? Self Switches used the map ID, the event ID and the switch's letter so I would assume that self variables should work the same way.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Karltheking4

Quote
║ To set a self variable for an event, you'll need to call this script on a ║
║ map event: ║
║ self_variable(id, value, oper)

?!?!?!?!?!?!?!

Blizzard

Nevermind, I just took a look at the code, it's doing that stuff automatically.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Karltheking4