Initializing, Saving, and Extracting Hashes

● ARCHIVED · READ-ONLY
Started by Zen Blood 8 posts View original ↗
  1. Good day everyone!

    I am having a heck of a time making custom variables and hashes (for scripts I've made) initiated upon beginning the game, saved, and then extracted properly. Thanks to help I received, I was able to figure out where to begin, but now I'm getting an error that I haven't been able to figure out how to fix myself.

    This is the error I receive.
    Error.png.16175c124720690077d8cd648e290292.png
    It only happens when including the line $lureobjects = contents[:lureobj] when extracting the save contents. The variable $lure_food isn't exactly the same as when I supposedly save it upon continuing the game, but it still serves its purpose so I won't worry about that at the moment.

    Here is how the script currently looks:
    Code
    Code:
      #--------------------------------------------------------------------------
      # * Create Game Objects
      #-------------------------------------------------------------------------- 
      def self.create_game_objects
        $game_temp          = Game_Temp.new
        $game_system        = Game_System.new
        $game_timer         = Game_Timer.new
        $game_message       = Game_Message.new
        $game_switches      = Game_Switches.new
        $game_variables     = Game_Variables.new
        $game_self_switches = Game_SelfSwitches.new
        $game_actors        = Game_Actors.new
        $game_party         = Game_Party.new
        $game_troop         = Game_Troop.new
        $game_map           = Game_Map.new
        $game_player        = Game_Player.new
        
        #MY OBJECTS (NO ERROR)
        #==========
        $lureobjects        = { }
        $lure_food          = "food"
        $event_to_erase     = 0
      end
     
      #--------------------------------------------------------------------------
      # * Create Save Contents
      #--------------------------------------------------------------------------
      def self.make_save_contents
        contents = {}
        contents[:system]        = $game_system
        contents[:timer]         = $game_timer
        contents[:message]       = $game_message
        contents[:switches]      = $game_switches
        contents[:variables]     = $game_variables
        contents[:self_switches] = $game_self_switches
        contents[:actors]        = $game_actors
        contents[:party]         = $game_party
        contents[:troop]         = $game_troop
        contents[:map]           = $game_map
        contents[:player]        = $game_player
        
        #MY OBJECTS (NO ERROR)
        #==========
        contents[:lureobj]       = $lureobjects
        contents[:lurefood]      = $lure_food
        contents[:event2erase]   = $event_to_erase
        #----------
        contents
      end
     
      #--------------------------------------------------------------------------
      # * Extract Save Contents
      #--------------------------------------------------------------------------
      def self.extract_save_contents(contents)
        $game_system        = contents[:system]
        $game_timer         = contents[:timer]
        $game_message       = contents[:message]
        $game_switches      = contents[:switches]
        $game_variables     = contents[:variables]
        $game_self_switches = contents[:self_switches]
        $game_actors        = contents[:actors]
        $game_party         = contents[:party]
        $game_troop         = contents[:troop]
        $game_map           = contents[:map]
        $game_player        = contents[:player]
        
        #MY OBJECTS
        #==========   
        $lureobjects        = contents[:lureobj] #(CAUSES ERROR)
        $lure_food          = contents[:lurefood] #(NO ERROR)
        $event_to_erase     = contents[:event2erase] #(NO ERROR)
      end

    I've got a lead on something about a "marshal dump" and I have heard about marshal dump in regards to RPGMVXA before, but I have not yet dealt with it myself. I'm still researching.

    Thank you for your time!
  2. I've moved this thread to Script Support. Thank you.

  3. I'm very sorry about that, thank you!
  4. a game_interpreter:1411 is usually a bad script call within an event.
    no error within *that* script, but you should *alias* those methods, not overwrite them.
    Code:
    module DataManager
     class << self
      alias orig_CGO create_game_objects
      alias orig_XSC extract_save_contents
      alias orig_MSC make_save_contents
     end
    
     def self.create_game_objects
      orig_CGO #call the original
      #add your modifications
      $lureobjects        = { }
      $lure_food          = "food"
      $event_to_erase     = 0
     end
    
     def self.extract_save_contents(contents)
      orig_XSC(contents)
      $lureobjects        = contents[:lureobj]
      $lure_food          = contents[:lurefood]
      $event_to_erase     = contents[:event2erase]
     end
    
     def self.make_save_contents 
      contents = {}
      contents = orig_MSC
      contents[:lureobj]       = $lureobjects
      contents[:lurefood]      = $lure_food
      contents[:event2erase]   = $event_to_erase
      return contents
     end
    end

    call the originals, then add your code after them
  5. The error you get is from a script call. That script call includes the "store" part, but the object that it's supposed to be called on is not created properly, so you get the error.

    I assume that you use other custom scripts, and one or more of them uses those methods you just overwrote, so the custom data for those custom scripts are not made at all, hence the error when you trigger that script call. But this is all just my guess, because...

    There are a lot of information you forgot to include:
    - When does the error trigger? (I know it happens when you trigger a script call, so this is covered).
    - What script call did you use exactly and which script does it belong to?
    - Where did you edit/add that script snippet you just posted? In the default script or did you add it in a new slot somewhere?
  6. Thank you both for your responses!

    gstv87 said:
    call the originals, then add your code after them

    It works! Thank you very much for taking time to help me figure this out. Would you perhaps be willing to check my logic on how this works? You've already done enough, so if you'd rather not I completely understand. I just want to make sure I'm comprehending what your re-written code is doing so I can be capable of helping myself more in the future.

    I hope switching the methods for extract_save_contents and make_save_contents doesn't change anything. It just helps me follow along better.

    • Confirming This Is How It Works
      [*]So, first, you're creating a new class in DataManager.
      [*]I know that "<<" is used to add a variable onto the end of an array, so in this case, is this adding the class into DataManager, rather than overriding a class?
      [*]That class contains three aliases of the existing methods create_game_objects, make_save_contents, and extract_save_contents.
      [*]When you alias, you can use any term of your choosing, correct? In this case it's orig_CGO, orig_MSC, and orig_XSC.
      [*]Now we're defining create_game_objects.
      [*]orig_CGO is called and all the contents created within the original method are now re-added to the method.
      [*]The new variables, hashes, ect; are added.
      [*]Now we're defining make_save_contents.

      [*]A hash called contents is made, and stored in it are the original contents of make_save_contents, with the symbols being used as the keys. I'm guessing this is how another key and value are added to the hash: hashname[:symbol] = variable
      [*]My symbols are then added.
      [*]return signals that hash contents has now been overridden with the new information.
      [*]Now we're defining extract_save_contents. It has a new parameter that includes the argument contents in it. This contents must also correspond with the hash contents when we defined make_save_contents somehow, correct?

      [*]My hashes and variables are added and set to equal the value of their symbols.
      [*]And voila!
  7. Zen Blood said:
    [*]So, first, you're creating a new class in DataManager.
    no.
    DataManager is a module, and it does't hold classes, it can only hold methods.
    modules are then called *from* classes, to run those methods externally
    what I did was to extend DataManager as a class so that I can use the alias instruction (which only works for classes)

    Zen Blood said:
    [*]I know that "<<" is used to add a variable onto the end of an array, so in this case, is this adding the class into DataManager, rather than overriding a class?
    yes and no.
    << is the same as array.push(value), yes, but in this case I'm stating that the class will be called DataManager and all the values within it will be passed down.
    basically, sucking DM's content into the new class.

    Zen Blood said:
    [*]That class contains three aliases of the existing methods create_game_objects, make_save_contents, and extract_save_contents.
    that class includes three new methods (those) (from the new perspective).
    any previous methods called that way now cease to be valid, except for the fact that I saved the original methods into new designations (alias)

    Zen Blood said:
    [*]When you alias, you can use any term of your choosing, correct? In this case it's orig_CGO, orig_MSC, and orig_XSC.
    yep

    Zen Blood said:
    [*]Now we're defining create_game_objects.
    [*]orig_CGO is called and all the contents created within the original method are now re-added to the method.
    [*]The new variables, hashes, ect; are added.
    we're going to *run whatever the method named orig_CGO is*, which is *the previous method create_game_objects as coded originally*

    Zen Blood said:
    [*]Now we're defining make_save_contents.
    [*]A hash called contents is made, and stored in it are the original contents of make_save_contents, with the symbols being used as the keys. I'm guessing this is how another key and value are added to the hash: hashname[:symbol] = variable
    a *variable* called "contents" is made, which will store *whatever the result of the method orig_MSC is*, which turns out to be the same thing as before.

    Zen Blood said:
    [*]My symbols are then added.
    [*]return signals that hash contents has now been overridden with the new information.
    "return" is basically "send this variable outside".
    what you have to follow is what process is this "contents" variable being sent out to, which is what will ultimately continue the program down the line, not this "contents" object particularly.
    internal variables can often be overlooked without issue.

    Zen Blood said:
    [*]Now we're defining extract_save_contents. It has a new parameter that includes the argument contents in it. This contents must also correspond with the hash contents when we defined make_save_contents somehow, correct?
    the "contents" stated in the declaration is what the variable will be called internally.
    again, what you have to watch for is what is being passed down *into* that variable, *from* the external process.
    in this case, they're both called the same, but it might not be.
    in this case, it must contain (when pulled from the save file) a data token for each of the indexes requested (which will be true, if the new MSC is ran correctly *before* restoring the save file *through* this new XSC..... if you had recieved an error here, that means one of the new indexes is not there, because the new MSC didn't run correctly, which can only happen if it's not called correctly from the original)

    take note that these are *declarations*, not *calls*.
    they're *not running* unless you *call* them from somewhere else, so they can be *declared* in whatever order.

    what's important in programming, is being able to understand that when a piece of data is being passed between functions, it's not "variable XXX" but rather "parameter X, of total Y, within the internal declaration of variables of this process, assigned by process calling this process, in process Z, with value V, type of data D"
    when you bring the object, you bring *the object* as a whole, so, read it as a whole and think about it as a whole.
    if you don't know what a given something is, read where it comes from.
    if it's still not clear, go a level above that, and above, and above, until you find where it comes from.
  8. Ah, that helps a lot! I appreciate the explanation. Thank you very much.
    Have a good one!