Initializing, Saving, and Extracting Hashes

Zen Blood

Certifiably Sane
Member
Joined
Jun 5, 2014
Messages
4
Reaction score
0
First Language
English
Primarily Uses
N/A
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.

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:
  #--------------------------------------------------------------------------
  # * 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!
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,536
First Language
English
Primarily Uses
RMMV

I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

Zen Blood

Certifiably Sane
Member
Joined
Jun 5, 2014
Messages
4
Reaction score
0
First Language
English
Primarily Uses
N/A
I'm very sorry about that, thank you!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,252
First Language
Spanish
Primarily Uses
RMVXA
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
 
Last edited:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
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?
 

Zen Blood

Certifiably Sane
Member
Joined
Jun 5, 2014
Messages
4
Reaction score
0
First Language
English
Primarily Uses
N/A
Thank you both for your responses!

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.

  • [*]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!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,252
First Language
Spanish
Primarily Uses
RMVXA
[*]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)

[*]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.

[*]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)

[*]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

[*]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*

[*]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.

[*]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.

[*]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.
 

Zen Blood

Certifiably Sane
Member
Joined
Jun 5, 2014
Messages
4
Reaction score
0
First Language
English
Primarily Uses
N/A
Ah, that helps a lot! I appreciate the explanation. Thank you very much.
Have a good one!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,231
Members
137,607
Latest member
Maddo
Top