Autosaves that display date and time

Started by xStaH, Tue 15/05/2007 09:07:57

Previous topic - Next topic

xStaH

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:

Code: ags

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.


GarageGothic

#1
Well, the year is missing from the String, but even with that it doesn't compile. Try:

Code: ags
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);
}

Ashen

#2
Nope, that just compounds the problem because it adds another parameter that SaveGameSlot can't handle. Try:
Code: ags

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. 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'.
I know what you're thinking ... Don't think that.

xStaH

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:

Code: ags

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!

SMF spam blocked by CleanTalk