[SOLVED] Setting system date as Save name

Started by shaun9991, Thu 27/01/2022 20:14:11

Previous topic - Next topic

shaun9991

Hey!

I'm probably missing something really obvious, but I'm trying to get the DateTime property into a String so I can use this for my "Autosave" function.

My current autosave function is like this:
Code: ags
 SaveGameSlot(1, savelocation);

With savelocation being defined as something like this, to define the "chapter" of the game the player is playing and the location when the game was saved.
Code: ags
savelocation = "AUTO: Arrival - Inn bedroom"; 


But I'd like try something like
Code: ags
 SaveGameSlot(1, "AUTO:" DateTime);


Obviously the above doesn't work, but I'm having trouble trying to define DateTime within a string I can use for the save name.

Does anybody have any ideas?

Many thanks!
Shaun
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Crimson Wizard

DateTime is a struct, you need to get an instance of one, and also retrieve some values, as it cannot format on its own.

Something like
Code: ags

DateTime *now = DateTime.Now;
String desc = String.Format("AUTO: %d / %d / %d / %d : %d : %d",
        now.Year, now.Month, now.DayOfMonth, now.Hour, now.Minute, now.Second);
Display("TEST: %s", desc); // just for a test
SaveGameSlot(1, desc);


shaun9991

Thank you so much CW, you're the best!

It worked immediately.



Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

SMF spam blocked by CleanTalk