Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Saving Object Hashes, lost.

Hi all,

The Problem: Can't access saved hashes.

Here's my object array, or hash, or whatever

Example:
Code:
$quest[1].name = "Choco Monkey"
$quest[1].description = "Find me a delicious chocolate monkey for my belly."

The above info has already been set.

Now, when I save the quest under the Scene_Save class in the SDK, the quest saves fine(or so I think), here's an example of my code under the write_data def:

Code:
Marshal.dump($quest, file)
p $quest[1].name #i already accepted this quest to test it.

And finally here's my load code under Scene_Load (read_data def):
Code:
$quest = Marshal.load(file)
p $quest[1].name

My problem:

The data has been saved, and the quest name was displayed via the "p" command during the saving process, BUT when I LOAD the data, $quest[1] returns NIL.

Now, the object itself returns "" (not nil) when using "p $quest.to_s" instead of "p $quest[1].name"

So the $quest object is loading, but the hash part of it was either not saved, or not loaded, or both.

I'm rather lost on this subject and I would be extremely grateful if someone could help.

Thanks in advance,

Webgovernor.
 

Jared

Member

First start:
Code:
file = File.open('Test.rxdata', 'w')
$quest = Array.new
$quest[1] = 'Choco Monkey'
Marshal.dump($quest, file)

Second Start:
Code:
file = File.open('Test.rxdata', 'r')
p ($quest = Marshal.load(file)) #output: "Choco Monkey"

I test it, it works without problems.

When you save more than one object in the same save data, you must read the objects in the same order like you save/write them. Check this on your script.
But usualy there should come an bug report if something during the load- or save-procedure don´t work.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top