Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaun9991 on Thu 27/01/2022 20:14:11

Title: [SOLVED] Setting system date as Save name
Post by: shaun9991 on Thu 27/01/2022 20:14:11
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) Select
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) Select
savelocation = "AUTO: Arrival - Inn bedroom";

But I'd like try something like
Code (ags) Select
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
Title: Re: Setting system date as Save name
Post by: Crimson Wizard on Thu 27/01/2022 20:36:51
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) Select

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);

Title: Re: Setting system date as Save name (SOLVED)
Post by: shaun9991 on Thu 27/01/2022 20:51:02
Thank you so much CW, you're the best!

It worked immediately.

(https://tinyimg.io/i/pjxUGXI.png)