I have a need for quite a bit of constant data in a game, and I'd love to implement it as part of the database rather than setting it up as a separate class or module and have the data populated as the game is being played.
These are my initial thoughts of what needs to be done ... would appreciate if some scripters can take a look and let me know what I've missed out, or if this is just not going to work for some reason.
Step 1 - define the class as part of RPG modulesimpy by adding the following script:
module RPG
class xyz
def initialize
@id = 0
@name = ""
... other attributes here
end
attr_accessor :id
attr_accessor :name
... other attributes here
end
end
Step 2 - Define a handler classI am thinking this should be a part of the same RPG::xyz class (within the RPG module) and would include functions to populate, manipulate and retrieve data within the class. Comparing this with Game_Actor and $data_actors, I want this to be the equivalent of $data_actors -> $data_xyz. There will never be a $game_xyz in use. I am not even sure if I need to have this at all, if I make all the attributes accessible, since the contents will not change during play.
Step 3 - Set up the initial dataThis is a rountine that's run once during design, and removed before the game is released. Its purpose is to create an array of objects instantiated from this class and populate the fields. In keeping with all the other databases, element 0 should be nil, I think. Once all the data is there, I should use a save_data("Data/xyz.rxdata") command to create my xyz.rxdata file in the same place as all the other database files.
Step 4 - Use the fileWhen all the other database files are loaded into the game, simply add a $data_xyz = load_data("Data/xyz.rxdata") command. It's then available to use throughout the game, will never change, and never needs to be saved. Make sure the Data/xyz.rxdata is packed up and shipped with the game, which should be done automatically when the game is compressed.
I think I can skip step 2, and my Scene_xyz will handle all the data itself (it's just looking stuff up). It sounds almost too easy. What haven't I thought of?