Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: TheDerman on January 17, 2006, 07:04:08 PM

Title: save name as scene name with date/time?
Post by: TheDerman on January 17, 2006, 07:04:08 PM
Is it possible to automatically set the save name to the current scene name?

I don't want to have the savename window - I just want the player to click the "empty" save slot and then it saves the game with the scene name.

Also, would it be possible to add the current date and time in the form "dd/mm/yy, 23:07" after the scene name to differentiate saves done in the same scene?

Any pointers? Thanks.
Title: Re: save name as scene name with date/time?
Post by: Mnemonic on January 17, 2006, 07:20:26 PM
Yes, it's possible. In fact, WME Demo 3D does just that :)

The relevant piece of code:

Code: [Select]
////////////////////////////////////////////////////////////////////////////////
function DoSave(Slot)
{
  var CanSave = true;
  if(Game.IsSaveSlotUsed(Slot)) CanSave = Game.QuestionBox("Do you want to overwrite the old savegame?");

  if(CanSave)
  {
    var Time = new Date();
    var Minutes = Time.GetMinutes();
    if(Minutes < 10) Minutes = "0" + Minutes;

    Game.SaveGame(Slot, Scene.Name + ", " + Time.GetDate() + "." + Time.GetMonth() + "." + Time.GetYear() + ", " + Time.GetHours() + ":" + Minutes);
    this.xResult = true;
    this.Close();
  }
}
Title: Re: save name as scene name with date/time?
Post by: TheDerman on January 17, 2006, 08:09:01 PM
I've got it working nearly - here's my save.script...

Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"

self.xResult = false;

var NumSlotButtons = 8;
var NumSavegames = 100;
var ScrollOffset = 0;
var SelectedSlot = -1;

SetState();

////////////////////////////////////////////////////////////////////////////////
on "close"
{
  for(var i=10; i>=1; i=i-1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(70);
   }
  this.AlphaColor = MakeRGBA(255, 255, 255, 0);
  self.Close();
}

////////////////////////////////////////////////////////////////////////////////
on "up"
{
  ScrollOffset = ScrollOffset - 1;
  SetState();
}

////////////////////////////////////////////////////////////////////////////////
on "down"
{
  ScrollOffset = ScrollOffset + 1;
  SetState();
}


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  var button;

  if(Keyboard.KeyCode==VK_ESCAPE){
    button = self.GetWidget("close");
    button.Press();
  }
}

////////////////////////////////////////////////////////////////////////////////
function SetState()
{

  var BtnUp = self.GetWidget("up");
  var BtnDown = self.GetWidget("down");

  var Thumbnail = self.GetControl("thumbnail");

  BtnUp.Disabled = (ScrollOffset <= 0);
  BtnDown.Disabled = (ScrollOffset+NumSlotButtons >= NumSavegames);

  for(var i=0; i<NumSlotButtons; i=i+1)
  {
    var SaveSlot = ScrollOffset + i;
    var SlotButton = self.GetWidget(i+1);

    SlotButton.Pressed = (SaveSlot==SelectedSlot);
    SlotButton.Text = SaveSlot;
    if(Game.IsSaveSlotUsed(SaveSlot))
      SlotButton.Text = Game.GetSaveSlotDescription(SaveSlot);
    else
      SlotButton.Text = "...empty...";
  }
}

////////////////////////////////////////////////////////////////////////////////
function DoSave(Slot)
{
  var Time = new Date();
  var Minutes = Time.GetMinutes();
 
  if(Minutes < 10) Minutes = "0" + Minutes;

  Game.SaveGame(Slot, Scene.Name + ", " + Time.GetDate() + "/" + Time.GetMonth() + "/" + Time.GetYear() + ", " + Time.GetHours() + ":" + Minutes);
  this.xResult = true;
  this.Close();
}

////////////////////////////////////////////////////////////////////////////////
on "1"
{
  DoSave(1);
}

on "2"
{
  DoSave(2);
}

on "3"
{
  DoSave(3);
}

on "4"
{
  DoSave(4);
}

on "5"
{
  DoSave(5);
}

on "6"
{
  DoSave(6);
}

on "7"
{
  DoSave(7);
}

on "8"
{
  DoSave(8);
}

Only problem now is that the game is saving on the slot underneath the one I select - so if I select slot 1, the game saves in slot 2.
Title: Re: save name as scene name with date/time?
Post by: Mnemonic on January 17, 2006, 10:57:15 PM
It seems the on "number" ... handlers are assuming the slots are numbered from 1, while the SetState uses numbering from 0. So changing it to:

Code: [Select]
  for(var i=1; i<=NumSlotButtons; i=i+1)
  {
    ...
    var SlotButton = self.GetWidget(i);
    ...

...might help, maybe? But I'm really sleepy now so I can be wrong ;)
Title: Re: save name as scene name with date/time?
Post by: TheDerman on January 18, 2006, 12:09:30 AM
Perfect - thanks.  ;D

Next question - any idea how I can put a savegame number in front of the scene name? I tried SelectedSlot which worked fine but then I realised that would only give numbers up to 8 (because I have 8 slots which are not related to the number of saves available), so it's no good obviously. I have 100 save games so I need to number them 1 to 100.

Thanks.
Title: Re: save name as scene name with date/time?
Post by: TheDerman on January 18, 2006, 12:38:53 AM
Ok, I sorted out the save number problem all by myself - yay - I'm really learning this coding stuff now.  ;D ::rock

Thanks.