RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Resolved] Creating my own RPG::xyz class

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 87
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 module
simpy by adding the following script:
Code: [Select]
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 class
I 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 data
This 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 file
When 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?
« Last Edit: September 14, 2009, 04:04:56 AM by shaz »
Always remember you're unique.
Just like everybody else.

*
Rep:
Level 87
Ha!  Works beautifully, without step 2.

I'll leave the topic, in case anyone has need to do something similar and wants the steps, or would like more info on what I've done.
Always remember you're unique.
Just like everybody else.