Hi,
In my database I added a new actorfield that I use here and there via DialogueLua. However, these fields don't exist in old saves.
Is it possible to add these new fields to old savegames when they are loaded somehow? Based on the version number of the database perhaps?
Thanks!
Save system and new actor fields
Re: Save system and new actor fields
Hi,
When loading a saved game, the Dialogue System will automatically add any new variables, quest entries, and SimStatus (if enabled) that you've added since the save, but it doesn't do the same for actor fields.
I recommend making a subclass of DialogueSystemSaver. Use this subclass instead of DialogueSystemSaver. Override the ApplyData(string) method to do something like this:
When loading a saved game, the Dialogue System will automatically add any new variables, quest entries, and SimStatus (if enabled) that you've added since the save, but it doesn't do the same for actor fields.
I recommend making a subclass of DialogueSystemSaver. Use this subclass instead of DialogueSystemSaver. Override the ApplyData(string) method to do something like this:
Code: Select all
using PixelCrushers.DialogueSystem;
using Language.Lua;
public class CustomDialogueSystemSaver : DialogueSystemSaver
{
public override ApplyData(string data)
{
base.ApplyData();
AddMissingActorFields();
}
public void AddMissingActorFields()
{
foreach (var actor in DialogueManager.masterDatabase.actors)
{
foreach (var field in actor.fields)
{
if (DialogueLua.GetActorField(actor.Name, field.title) == LuaNil.Nil)
{ // Field isn't in Lua, so add it:
switch (field.type)
{
case FieldType.Boolean:
DialogueLua.SetActorField(actor.Name, field.title, Tools.StringToBool(field.value));
break;
case FieldType.Actor:
case FieldType.Item:
case FieldType.Location:
case FieldType.Number:
DialogueLua.SetVariable(actor.Name, field.title, Tools.StringToFloat(field.value));
break;
default:
DialogueLua.SetVariable(actor.Name, field.title, field.value);
break;
}
}
}
}
}
}
Re: Save system and new actor fields
Superb! Thanks!
Re: Save system and new actor fields
To be complete, I made it a little shorter:
Code: Select all
using PixelCrushers.DialogueSystem;
public class GotsDialogueSystemSaver : DialogueSystemSaver
{
public override void ApplyData(string data)
{
base.ApplyData(data);
AddMissingActorFields();
}
public void AddMissingActorFields()
{
foreach (var actor in DialogueManager.masterDatabase.actors)
{
foreach (var field in actor.fields)
{
if (!DialogueLua.GetActorField(actor.Name, field.title).hasReturnValue)
{ // Field isn't in Lua, so add it:
DialogueLua.SetActorField(actor.Name, field.title, field.value);
}
}
}
}
}
Re: Save system and new actor fields
Looks good! If your fields are numbers or Booleans, consider using the switch statement in my previous reply. This will ensure that the right type gets assigned in Lua.