Harlowe 3.1 Saving/Loading Variables

I’m making a Pokemon-inspired game, and wanted to have a load/save function. But I found out that the load/save on the Harlowe guide doesn’t save my variables. Is there anyway I could do this? Thanks!

1 Like

and wanted to have a load/save function.

I’m assuming you know about using the (save-game:) macro to save the current state of History and using the (load-game:) macro to replace the current state of History with the one store in a save.

I found out that the load/save on the Harlowe guide doesn’t save my variables.

Could you explain in greater detail what lead you to believe the above, possibly with example source code from your project demonstrating any issues you are having and the type of variable/values you’re having them with.

Hi @Greyelf ! Thanks for responding! Yeah, so I was trying the load/save macro, and it saved my passage, but not the variables. Example, if a user got a map (set: $map to true), when the user would save and load the game, all the variables were set to 0, so $map would be 0/false, not true. Thanks in advance!

The (save:) macro saves the current state of (History) all known story variables as they were just before the contents of the current Passage was processed and shown. So if your $map variable was assigned a value before the current Passage was navigated to then that should be the value that variable is reset yo when that save is loaded.

eg. If $map was equal to true before the current passage was navigated to then that should be the value saved within a save generated for the current passage.

After the loading of a save has finished updating the History the load code navigates to the Passage associated with that save, this results in that Passage becoming the ‘current’ one and the contents of that passage being re-processed/executed.

So when you were testing the save/load functionality did:

  1. The $map variable have a value of true before you navigated to the Passage you created the save for.
  2. Did the Passage you created the save for contain code that changed the value of $map
1 Like

Hi! I followed what you said, and now it is working! Thanks!

Hi there,

I seem to be running into a similar issue here with my own project. I don’t have a problem saving my game the first time through, but loading a save file and then trying to save again is giving me this error message:

The variable $new_float_box,[object Object] holds an empty variable (which is, or contains, a complex data value) on turn 2; the game can no longer be saved.

For reference, I’ve got some start-up code that looks like this, which I’m using throughout my story:

(set: $new_float_box to (floatbox: “=XX=”, “=YYYYYY==”)+(text-size: 0.8)+(textcolour: “#eae1e3”)+(corner_radius: 3)+(font: “Bahnschrift Light”)+(align: “<==”))

I came across an old post on the Twine forum where someone explained that Harlowe doesn’t like saving variables which aren’t “strings, numbers, booleans, arrays, datamaps or datasets,” but I can’t find where in the documentation this is explained in more detail. Am I getting this error because I’m trying to save a changer?

I’m wondering if maybe I should try the (move: $complexVariables to _dump) trick, and have that run just before saving? And then re-initialize the changer variables after loading? Do you think that would work?