0 votes
by (490 points)

I'm not sure if this is just me having bad luck finding the information I'm looking for (entirely possible, none of my search attempts seem to be presenting me with anything even close to what I'm looking for), or if I'm just that bad at figuring out this save-game stuff (also possible, as this is the first time I've tried adding a 'save game' option to something).

 

What I want to do is fairly simple: for there to be multiple slots for people to save their games to, each identified on the loading screen by a name the player chooses for that game.

What I can't figure out is how to get the (load-game:) macro to work with what I'm doing right now without me somehow magically knowing what name the players used for their characters. I also really think someone needs to go do some editing to the Harlowe manual, because I'm pretty sure the save-game section, at least, is confusing the daylights out of more than just me. It seems it would work fine (mostly; may need some modifications) for a single saved game, but not for multiple files. I would like to note that it implies you can use multiple strings when saving a game, which I assume is a part of how I solve my current problem. The manual says, and I copy-paste, "(save-game:)'s first string is a slot name in which to store the game." It then never mentions anything about what you can and cannot do with a second string.

I'm also not sure how to make sure the player is saving to the right save slot when saving their game, assuming they have multiple games saved.

What I'm using right now for saving is in a 'header' passage and then appended to the ?sidebar. (It's also sitting in said ?sidebar with a few other handy links.)

(link: "Save Game")[
	(if: (save-game: $Name))[Game saved!]
	(else:)[Sorry, I couldn't save your game.]]

This clearly works, because I was playing around earlier and saved a file under the name 'Kynvyn'.

However, I cannot recall that game except by using the specific name now.

This is what works:
(link: "Load a Started Crawl")[
	(print: (saved-games:))
	(link: "Load Game: " + "Kynvyn")[
		(load-game: "Kynvyn")]
]

This, which is basically what the manual tells you to do (albeit with a couple edits)... doesn't.
(link: "Load a Started Crawl")[
	(print: (saved-games:))
	(link: "Load Game: " + ($Name) of (saved-games:))[
		(load-game: $Name)]
]

Please note two things about this that are also confusing the daylights out of me:

1) Printing (saved-games:) presents me with this: Kynvyn``
Why are there backticks?

2) Why does the manual put (parentheses) around the Slot #/File Name?

 

Any help on this would be appreciated, since I've once again found the point where I'm just going in circles testing the same five things over and over again with the same (ineffective) results.

1 Answer

0 votes
by (159k points)
selected by
 
Best answer

It then never mentions anything about what you can and cannot do with a second string

There is information about the second String (file name) parameter in the Details section of the  (save-game:) documentation.

Giving the saved game a file name is optional, but allows that name to be displayed by finding it in the $Saves datamap. This can be combined with a (load-game:)(link:) to clue the players into the save's contents:

Of simply put, you can use the second String parameter to associate a (more meaningful) file name with each save you create, and that file name can be access as the value part of each key/value pair contained within the date-map returned by the (saved-games:) macro. So assuming that you used TwineScript like the following to create a Save.

(link: "Save Game")[
	(if: (save-game: 'The Slot Name', 'The File Name'))[Game saved!]
	(else:)[Sorry, I couldn't save your game.]
]

... then you could use TwineScript  like the following to display a list of the Save Slots associated with the story, and the File Name associated with each of the Save Slots.

Saves Slots: {
(set: _saves to (saved-games:))
(for: each _name, ...(datanames: _saves))[
	<br>Slot: _name - File Name: (print: _saves's (_name))
]
}

 

Why are there backticks?

Because both parts of the above mentioned key/value pair have a data-type of String and in your example the value (file name) part is empty, so the (print:) macro is displaying that value as two back-ticks with nothing between them.

Why does the manual put (parentheses) around the Slot #/File Name?

You can use parentheses to control the order that the individual parts of a complex expression get processed in.

In the case of the example within the Details section of the (save-game:) documentation the writer wanted the file name of the relevant Save to be determine first, so that String value could then be appended to the end of the "Load game: " String literal, and the resulting String value could then be passed as the first parameter of the (link:) macro.

Now to answer your question about how to create Load links for saves that the player supplied the Slot Names of.

Assuming that the Save was created using TwineScript something like the following...

(set: $slotName to "Banana")
(link: "Save Game using variable Slot Name")[
	(if: (save-game: $slotName, 'Variable based Slot Name'))[Game saved!]
	(else:)[Sorry, I couldn't save your game.]
]

... then you could use TwineScript like the following to display each of the Save key/value pairs within the (save-games:) data-map...

{
(set: _saves to (saved-games:))
(for: each _name, ...(datanames: _saves))[
	<br>
	(print: 
		"(link: 'Load Game: " + (_saves's (_name)) + "')[" +
			"(load-game: '" + _name + "')" +
		"]"
	)
]
}

NOTE: The reason why a (print:) macro is used to dynamically create each (link:) is because the body of a link isn't executed until after the end-user selects it, and value of any variable reference in that body isn't determined until that selection occurs. This means that the value of the above _name variable will be exactly the same for all the links created by the (for:) macro loop.

To get around this issue we need to capture the current value of the _name variable for each iteration of the for loop, but unfortunately Harlowe doesn't have such a feature so the Stupid Print Trick (tm) is used as a substitute instead.

by (490 points)

Thank you. I'm still of the opinion that the referenced section of the manual is poorly worded, but this clears it up nicely.

Stupid Print Trick (tm)

And... this made me laugh harder than it probably should have. I'm not saying it's not appropriate, but it's still funny.

by (159k points)

...this made me laugh...

You have TheMadExile to thank for that term, it was first used during an earlier period in the development of Harlow.

...