How to give a save slot the name of the value of a var?

Started by Kumpel, Mon 31/07/2017 15:29:27

Previous topic - Next topic

Kumpel

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 

horusr

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.

Crimson Wizard

#2
Yes, this is exactly like

Code: ags
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

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.

SMF spam blocked by CleanTalk