deengames / a-day-and-a-night

Top-down adventure game based around a day and night in a small village. With epic dragons, an evil empire, and a rousing rebellion.
7 stars 5 forks source link

Custom Save Data #121

Closed ashes999 closed 10 years ago

ashes999 commented 10 years ago

The problem with our points system is that points don't save. We need to save them. This won't be the only thing we're saving, so we need a way to save/load custom bits of data with the player's save game.

I thought about this a lot. There are different things we can do, like giving the user the ability to differentiate "saved" vs. "will be saved" or "loaded from save" vs. "loaded value was X but current value to save is Y." Ultimately, all these things are unnecessary, and we should give the user an easy-to-understand interface.

Let's go with something simple:

SaveGame.set(key, value)
SaveGame.get(key) => value

Internally, when you load save data, just unpack contents into a new hash in memory (which you're doing now). set should just write to that array, and get should just read from it. When you save, save it.

This gives us a consistent interface. If you tell the save game system "hey save this value," then you say "hey what's that value," you should get that value. Getting the old value (from the last time the user saved) is just confusing.

Because the user can save any time, this means any data which must be consistently saved must be stored here. For example, for our points system, we should just be reading/writing to SaveGame as far as storing the actual data.

P.S. Please, no French, it's not maintainable after you stop contributing.

ashes999 commented 10 years ago

Please critique my updated description @Haris1112 and let me know if you have any questions. I've greatly simplified it; you shouldn't need @objects etc., just keep the internal contents structure and we're good.

Please let me know. I want to try and finalize this so we can get it done, and then implemented.

Wulf commented 10 years ago

Roger.

ashes999 commented 10 years ago

lolwut, I don't need a "roger," I need a critical analysis of the design.

You know RPG Maker better than me (at least the scripting-side -- I don't even know how you found these functions), you are the best person to figure out the right design from the RPG Maker API perspective.

Wulf commented 10 years ago

What we currently have has a very hacky feel to it. I'd rather we stick to what we had before. I agree with what you said, and would probably add on that having the variables live on the object would be more natural from the perspective of someone foreign viewing the script on some web site. I.E. the script does what it sounds like it does. 'SaveGame.set_variable' and 'SaveGame.get_variable'. The SaveGame describes a non-persistant saving system.

As for me being the rgss champ, woohoo! But it only takes just a few minutes :P Start reading from the Main script, and follow through! Why's Poignant guide says Ruby is the most readable language; couldn't agree more haha. Also, I only read through what I needed to know. I like to understand how the car engine works while I drive :P

Wulf commented 10 years ago

When I say 'what we had before.' It is basically what you describe, but your version is moar refined :)

ashes999 commented 10 years ago

Ok great, so if you're okay with the API described in this issue, let's do this!!!

:+1:

Wulf commented 10 years ago

Let's do this!!

ashes999 commented 10 years ago

:stuck_out_tongue_closed_eyes:

Wulf commented 10 years ago

"you shouldn't need @objects etc., just keep the internal contents structure and we're good."

I don't understand this.

ashes999 commented 10 years ago

Very well. Since I can't explain it well enough, perhaps code will suffice. I think this is 90% or so of the code we need. We don't need a SaveGame module any more.

Thoughts?

module DataManager

  @@contents = {}

  # Loading
  class <<self
    alias :load_contents :extract_save_contents
  end

  def self.extract_save_contents(contents)
    load_contents(contents)
    contents.each do |k, v|
      @@contents[k] = v
    end
  end

  # Saving
  class <<self
    alias :save_contents :make_save_contents
  end
  def self.make_save_contents
    original_contents = save_contents
    @@contents.each do |k, v|
      original_contents[k] = v
    end
  end

  def get(key)
    return @@contents[key]
  end

  def set(key, value)
    @@contents[key] = value
  end
end
Wulf commented 10 years ago

LOL, that's definitely clear enough! XD

ashes999 commented 10 years ago

lulz.

You need to actually try it (I didn't check if it has runtime errors) and experiment with it -- save some data, load it, etc. and make sure it works.

:)

Wulf commented 10 years ago
# LOADING

contents.each do |k, v|
  @@contents[k] = v
end

versus

@@contents.each do |k, v|
  @@contents[k] = contents[k]
end

Argument: This will only load the kingdom points, deed points, etc,data to contents, like we want. All the other loaded data won't be loaded onto thisvariable like actor data.

Also,

original_contents = save_contents
@@contents.each do |k, v|
  original_contents[k] = v
end

Can I name original_contents just contents to have consistency throughout the script?

Wulf commented 10 years ago

Is it just this script, or has the whole game changed colours?

Also, thanks for the link for that video on aliasing.

Wulf commented 10 years ago

Okay, I can give a semi confirmation that it is not this script. @ashes999 please create an issue regarding custom bars script.

ashes999 commented 10 years ago

Sure, you can rename it contents.

I don't care about actor data etc. We don't need it. And it should still be loading. I wouldn't spend more time on it now (we spent too much time on this) especially since we don't need it.

Can you create an issue for the custom bars script? I don't know what exactly you're asking about.

Wulf commented 10 years ago

I wouldn't know what to write other than: repro case: start new game, menu>exit to title, colours are messes up.

ashes999 commented 10 years ago

Please open an issue and include a screenshot. You need a better repro case, because these steps don't cause any issue for me.

Wulf commented 10 years ago

Seems to have fixed itself haha :)

ashes999 commented 10 years ago

I can confirm that I tested the points stuff a couple of days ago and it looks good.

:+1: