Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kumpel on Mon 31/07/2017 15:29:27

Title: How to give a save slot the name of the value of a var?
Post by: Kumpel on Mon 31/07/2017 15:29:27
I have a variable that serves as a counter and works like some kind of process bar. Now I want to create a save slot with this exact current value as its name. Just doing SaveGameSlot(PBCounter,"%d", PBCounter) doesn't seem to work when I test the game. It says I have the "wrong number of parameters". Doing "" instead gives me a blank list item at the list of restorable save files.

How do I autoname a savegame like this then?

Cheers
Kumpel 
Title: Re: How to give a save slot the name of the value of a var?
Post by: horusr on Mon 31/07/2017 15:46:28
This is probably a long shot but when you add "," to format string it takes that as paramater. Can you try String.Format("%d", PBCounter)? I don't know if it works but worth trying.
Or you can simply wait for Khris to answer.
Title: Re: How to give a save slot the name of the value of a var?
Post by: Crimson Wizard on Mon 31/07/2017 16:07:39
Yes, this is exactly like

Code (ags) Select
SaveGameSlot(PBCounter, String.Format("%d", PBCounter));

String.Format returns a formatted string, which is in turn used as a second argument to SaveGameSlot, which is a shorter way of doing -
Code (ags) Select

String s = String.Format("%d", PBCounter);
SaveGameSlot(PBCounter, s);

(more elaborate, but longer variant)


Similarily you can create formatted string anywhere. There is just limited number of functions that allow to format a string right away, like Display and Say.