Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Trouble with saving/loading/displaying saves in Harlowe, Twine 2.0

edited February 2016 in Help! with 2.0
I'm having some issues saving a game, loading it, and displaying current saves for the player to load. I've read the documentation on Harlowe of how to do this, but still can't manage it. Here's what I have:

Start Passage:
(set: $playerName to (prompt: "Choose your name:"))
(set: $class to (prompt: "Choose your class:"))
<==
''{(link:"Save")[
(if: (saved-games:) contains "File A")[(save-game: "File B", "$playerName, the $class")[Saved in File B]]
(else: )[(save-game: "File A", "$playerName, the $class")[Saved in File A]]
]}''
\
==>
''Load->View Saves''

=><=
''Hello''





View Saves:

=><=
''Saved Games''



<==
(if: (saved-games:) contains "File A")[
(print: (saved-games:)'s "File A")]
''(link: "Load")[(load-game: "File A")]''

(if: (saved-games:) contains "File B")[
(print: (saved-games:)'s "File B")]
''(link: "Load")[(load-game: "File B")]''





The issue is, when I insert my name and class, it sets it to the correct variables, then i save and everything's fine. Except when I create a secondary save, it saves to File B, so not to overwrite File A, but completely updates all the variables to the variables that were just inserted. So the player name and class being displayed for both File A and File B, are the same, and not the unique, individual variables for File A and File B. File A and File B no longer have their own, separate inputs for $playerName and $class, they share the same input. I'm sorry if this sounds confusing. But the variables themselves stay the same. When I load up File A, it has the same variables that it had, the exact same as when I saved File A. The same occurs for File B. However, when I'm on the screen to load my game, it is displaying the data for File A and File B. But it displays the $playerName and $class as the same variable input. Not the unique variable input that each save respectively holds.

I would like File A to display, say, "Billy" for $playerName and "Archer" for $class. While File B displays "Jack" for $playerName and "Warrior" for $class. Yet, they both display "Jack" and "Warrior". However, loading either file does give them back their separate "Billy" and "Jack" variable inputs.

I apologize for any confusion and thank you in advance for any assistance you can provide.

Comments

  • Please use the C button in the toolbar above the comment text area to wrap your code examples in code tags, it makes reading the code easier.

    You have two issues:

    1. When the variables within the "$playerName, the $class" string are being evaluated.

    The values of the variables within that string are not being substituted into the string when you use the (save-game:) macro, the macro is saving the string as is. The variable values are being substituted when you do the (print: (saved-games:)'s "File A"), so the current values of those variables are used.

    This can be seen in the following example, the output of the last line should be abcde, the efghi and not Billy, the Archer as you would expect:
    (set: $playerName to "Billy")
    (set: $class to "Archer")
    (save-game: "File A", "$playerName, the $class")
    (set: $playerName to "abcde")
    (set: $class to "efghi")
    (print: (saved-games:)'s "File A")
    
    ... this can be fixed by changing the (save-game:) macro to something like the following, which causes the variables to be evaluated at the time the macro is used:
    (save-game: "File A", $playerName + ", the " + $class)
    

    2. The (save-game:) macro does not only save the values of the story's variables, it also remembers the name of the Passage that was being shown when the (save-game:) macro was used/called. So when you use a (load-game:) macro, you are not only restoring the story variable's values, you are also redisplaying that Passage which will cause any code within that Passage to be run again which can result in the restored variables being overwritten by any code in that Passage.

    Because of this I would suggest having the (save-game:) macros within a passage that does not contain any (set:) macros.
  • Ah, I see. It works perfectly! Thanks for all the help and sorry about the code being inserted weird, I'll remember the C next time.
Sign In or Register to comment.