Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: xStaH on Tue 15/05/2007 09:07:57

Title: Autosaves that display date and time
Post by: xStaH on Tue 15/05/2007 09:07:57
Hi all,

So I'm the first to admit that I am a complete nOOb and this stuff.  But I have a question.  I am trying to make an autosave feature that will append the current date and time to the "autosave" name.  (So it would look like this in the restore GUI;   "Autosave from 05/15 at 2:54".

The code I started with looks like this:


if (GetGraphicalVariable("ParentsRoom") == 1) {
DateTime *dt = DateTime.Now;
SaveGameSlot(99, "Autosave from %02d/%02d at %02d:%02d", dt.DayOfMonth, dt.Month,                 
         dt.Year, dt.Hour, dt.Minute);
}

Right away this looked too clumsy to me. And of course I get the error "The wrong number of parameters is called to SaveGameSlot".  But I've searched for an hour now and can't find out how I could do this, though I am sure its a simple fix.  Any suggestions or places you could direct my searches?  Thanks guys.

Title: Re: Autosaves that display date and time
Post by: GarageGothic on Tue 15/05/2007 09:57:59
Well, the year is missing from the String, but even with that it doesn't compile. Try:

if (GetGraphicalVariable("ParentsRoom") == 1) {
DateTime *dt = DateTime.Now;
        String savegamename = String.Format("Autosave from %02d/%02d/%02d at %02d:%02d", dt.DayOfMonth, dt.Month,          dt.Year, dt.Hour, dt.Minute);
SaveGameSlot(99, savegamename);
}
Title: Re: Autosaves that display date and time
Post by: Ashen on Tue 15/05/2007 10:01:27
Nope, that just compounds the problem because it adds another parameter that SaveGameSlot can't handle. Try:

if (GetGraphicalVariable("ParentsRoom") == 1) {
DateTime *dt = DateTime.Now;
        String Temp = String.Format("Autosave from %02d/%02d/%02d at %02d:%02d", dt.DayOfMonth, dt.Month, dt.Year, dt.Hour, dt.Minute);
SaveGameSlot(99, Temp);
}


EDIT:
Oh, and a search for "date in save name" brings up this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=30666.0). It's not quite the same but close enough.

EDIT 2:
Added another %02d for year, since the dt.Year is there, but I'm not sure how that'll look with a 4-digit year.
Going on the first post ("So it would look like this in the restore GUI;   "Autosave from 05/15 at 2:54".") is it even wanted? And, the post says 'month;date' format, the code does 'date/month'.
Title: Re: Autosaves that display date and time
Post by: xStaH on Tue 15/05/2007 15:43:25
Wow guys, thanks for the quick response! Ashen, yours worked perfectly.  I'll have to mess with the formatting because the text runs outside the GUI load screen, but thats easy enough.   You are right though, having the year in there makes it look clunky.   You know, maybe just the time would be enough. How much info do you need from a temporary autosave anyway.  I just tested that and it looks a lot better.  Now it says "Autosave from hour:min" and the code is:


if (GetGraphicalVariable("ParentsRoom") == 1) {
DateTime *dt = DateTime.Now;
         String Temp = String.Format("Autosave from %02d:%02d", dt.Hour, dt.Minute);
SaveGameSlot(99, Temp);
}


That works perfectly though.  Thank you guys!! I knew it had to be an easy fix that I just wasn't seeing!