04-04-2013, 03:50 AM (This post was last modified: 09-02-2024, 10:27 PM by DerVVulfman.)
DerVVulfman's Game Data Sneak
Version: 1.0
Introduction
This is not an actual script that is used within a game, but a new method that can be used by scripters to 'sneak' new data classes into their games. This simple system can relieve scripters of the headaches of aliasing the save_game_data and load_game_data methods in the Scene_Load and Scene_Save classes by merely attaching the data to the Game_System class since the Game_System class itself is always stored in the save data files.
Script
The Game Data Sneak
Code:
#==============================================================================
# ** DerVVulfman's Game Data Sneak
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 04-02-2013
# All RGSS??? (Name of method that creates game pending between versions.)
#------------------------------------------------------------------------------
# This is not an actual script that is used within a game, but a new method
# that can be used by scripters to 'sneak' new data classes into their games.
# This simple system can relieve scripters of the headaches of aliasing the
# save_game_data and load_game_data methods in the Scene_Load and Scene_Save
# classes by merely attaching the data to the Game_System class since the
# Game_System class itself is always stored in the save data files.
#
# With the example script below, you can create a call of:
# p $game_system.data_object.my_data
#
# --- ( No, you will not use $game_data.my_data ) ---
#
#
# This works because the Game_Data class is stored in Game_System as the
# data_object value. And the my_data value within the Game_Data class is now
# a subvalue accessed from the data_object value itself.
#
# Likewise, you can also perform the following script call:
# $game_system.data_object.my_data = 5
#
# And again, this works. Not only that, but the data changed here will be
# saved as the data is recorded within the Game_System class which is saved
# and loaded normally.
#
# When aliasing, please make your aliased method names nice and unique. ^_^
#
#==============================================================================
# THANKS to Kain Nobel who kinda gave me the idea by accident. Haha...
# He loved it when I suggested it. Saves us a lot of grief.
#==============================================================================
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :data_object # Data Object of some class
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias data_initialize initialize
def initialize
# Perform the original call
data_initialize
# Create the attachment value
@data_object = nil
end
end
#==============================================================================
# ** Game_Data
#------------------------------------------------------------------------------
# This class holds some arbitrary data you wish to use and store.
#==============================================================================
class Game_Data
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :my_data # A piece of data within the class
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Sample data
@my_data = 0
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias data_command_new_game command_new_game
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
def command_new_game
# Perform the original call
data_command_new_game
# This attaches the new game data into Game_System
$game_system.data_object = Game_Data.new
end
end
Instructions
Scripters shouldn't find it too difficult. There are instructions in the script.
Compatibility
Given the simplicity, this 'method' should work with all RPGMaker systems though some naming conventions may change from system to system. And because it doesn't require the aliasing or either the save_game_data or load_save_data methods, you shouldn't have any issues as what data loads first.
Credits and Thanks
Thanks to Kain Nobel who kinda gave me the idea by accident.
Author's Notes
Remember, this is a method to add new data classes to scripts without needing to alter the save and load methods. Intended for scripter's usage only.
Terms and Conditions
Free for use, even in commercial scripts. Due credit is all that's required.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)