Need to extract a variable value from savegame data string

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Need to extract a variable value from savegame data string

Post by Abelius »

Hi there,

I'm using PlayMaker and EasySave3 to save my game state, so I've settled with using the actions "Record Savegame Data" and "Apply Savegame Data" to include DS in my save files.

All good.

Now, a need has arisen to access the values of some DS variables BEFORE loading the saved game. This is for previewing purposes (show some player stats, the day and period of the game, etc).

But of course that data is all inside the extremely long string DS provides to EasySave3 with the aforementioned actions.

Now, I've tried to make a value "extractor" resourcing to some pathetic actions like String Split, String Left, etc... and it didn't work very well, to be honest. :lol:

So, how could I access a given variable value inside that string in a proper civilized way?
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need to extract a variable value from savegame data string

Post by Tony Li »

Hi,

If you don't mind doing a little scripting, you can get it like this:

Code: Select all

using PixelCrushers; // (Put at top of script.)
using PixelCrushers.DialogueSystem;
...
//--------------------------------
// In this example, we'll get a variable from slot 1:
SavedGameData data = SaveSystem.storer.RetrieveSavedGameData(1);

// Assume the Dialogue System Saver's Key is "ds":
string s = data.GetData("ds");

// If you don't mind overwriting the current Lua environment, use this:
PersistentDataManager.ApplyLuaInternal(s, false);

// ...then get the variable:
string value = DialogueLua.GetVariable("My Variable Name").asString;

//--------------------------------
// Otherwise you'll need to create a temporary Lua environment:
Language.Lua.LuaTable tempLua = Language.Lua.LuaInterpreter.CreateGlobalEnviroment();
Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
string luaCode = "return Variable[\"My_Variable_Name\"]";
string value2 = Language.Lua.LuaInterpreter.Interpreter(luaCode, tempLua).ToString();
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Need to extract a variable value from savegame data string

Post by Abelius »

I'll try with the second example, because I don't want to overwrite anything.

But you're talking about "slots" in there, and I'm not using DS save system... What I have is the save game data, but in string format.

So, that SavedGameData data = ... I don't know what to put following that.
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need to extract a variable value from savegame data string

Post by Tony Li »

If your scene has a Save System component and a Dialogue System Saver component, use this:

Code: Select all

using PixelCrushers; // (Put at top of script.)
using PixelCrushers.DialogueSystem;
...
//--------------------------------
string savedString = //*** Get your data from ES3 here ***
SavedGameData data = JsonUtility.FromJson<SavedGameData>(savedString);

// Assume the Dialogue System Saver's Key is "ds":
string s = data.GetData("ds");

//--------------------------------
// Create a temporary Lua environment to process the data:
Language.Lua.LuaTable tempLua = Language.Lua.LuaInterpreter.CreateGlobalEnviroment();
Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
string luaCode = "return Variable[\"My_Variable_Name\"]";
string value2 = Language.Lua.LuaInterpreter.Interpreter(luaCode, tempLua).ToString();
If your scene does not have those components, use this:

Code: Select all

using PixelCrushers; // (Put at top of script.)
using PixelCrushers.DialogueSystem;
...
//--------------------------------
string s = //*** Get your data from ES3 here ***

//--------------------------------
// Create a temporary Lua environment to process the data:
Language.Lua.LuaTable tempLua = Language.Lua.LuaInterpreter.CreateGlobalEnviroment();
Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
string luaCode = "return Variable[\"My_Variable_Name\"]";
string value2 = Language.Lua.LuaInterpreter.Interpreter(luaCode, tempLua).ToString();
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Need to extract a variable value from savegame data string

Post by Abelius »

Well... I think I'm close, but I'm getting stack overflow exceptions:

Image

This is the code for the PlayMaker action I've created, using the "Apply Savegame Data" action as a template:

Code: Select all

using UnityEngine;
using HutongGames.PlayMaker;

namespace PixelCrushers.DialogueSystem.PlayMaker
{

    [ActionCategory("Dialogue System")]
    [HutongGames.PlayMaker.TooltipAttribute("Get a variable value from DS savegame data stored in a string variable.")]
    public class GetVariableFromSavegameData : FsmStateAction
    {

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("The PM string variable containing the DS savegame data")]
        public FsmString savedString;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("The DS variable name to get the value from")]
        public FsmString varName;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("A PM string variable to store the variable value in")]
        public FsmString value;

        public override void Reset()
        {
            savedString = null;
            varName = null;
            value = null;
        }

        public override void OnEnter()
        {
            if (savedString != null)
            {
                SavedGameData data = JsonUtility.FromJson<SavedGameData>(savedString.Value);
                string s = data.GetData("DSSaveSystem");

                Language.Lua.LuaTable tempLua = Language.Lua.LuaInterpreter.CreateGlobalEnviroment();
                Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
                string luaCode = "return Variable[\"Day\"]";
                value.Value = Language.Lua.LuaInterpreter.Interpreter(luaCode, tempLua).ToString();
            }
            Finish();
        }
    }
}
It looks like the stack overflow is happening when executing this line:

Code: Select all

string luaCode = "return Variable[\"Day\"]";
I actually started by substituting Day with varName.Value, but tried with just Day to make sure that wasn't the problem.

At any rate, I'm seeing the data seems to be get correctly (?) judging from this:

Image

But the last line returning the variable value doesn't get the chance the run.

Aaand... I'm going to bed. :roll:
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need to extract a variable value from savegame data string

Post by Tony Li »

I missed two things:

1. Need to clean up the quotes in the string, and
2. Need to initialize the Item[] table.

Try this:

Code: Select all

using UnityEngine;
using HutongGames.PlayMaker;

namespace PixelCrushers.DialogueSystem.PlayMaker
{

    [ActionCategory("Dialogue System")]
    [HutongGames.PlayMaker.TooltipAttribute("Get a variable value from DS savegame data stored in a string variable.")]
    public class GetVariableFromSavegameData : FsmStateAction
    {

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("The PM string variable containing the DS savegame data")]
        public FsmString savedString;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("The DS variable name to get the value from")]
        public FsmString varName;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.TooltipAttribute("A PM string variable to store the variable value in")]
        public FsmString value;

        public override void Reset()
        {
            savedString = null;
            varName = null;
            value = null;
        }

        public override void OnEnter()
        {
            if (savedString != null)
            {
                SavedGameData data = JsonUtility.FromJson<SavedGameData>(savedString.Value);
                string s = data.GetData("DSSaveSystem");
				
                s = s.Replace("\\\"", "\""); // *** Clean up quotes ***

                Language.Lua.LuaTable tempLua = Language.Lua.LuaInterpreter.CreateGlobalEnviroment();
				
                Language.Lua.LuaInterpreter.Interpreter("Item = {}", tempLua); // *** Initialize Item[] table ***
				
                Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
                string luaCode = "return Variable[\"Day\"]";
                value.Value = Language.Lua.LuaInterpreter.Interpreter(luaCode, tempLua).ToString();
            }
            Finish();
        }
    }
}
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Need to extract a variable value from savegame data string

Post by Abelius »

I still get an exception, I'm afraid.

I've copied the whole thing from the console, down here:

Code: Select all

[Exception] StackOverflowException: The requested operation caused a stack overflow.
Assignment.SetKeyValue()

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }

Assignment.SetKeyValue() at /Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:114
112:       else
113:       {
-->114:           SetKeyValue(newIndex, key, value);
115:       }
116:   }
At first I thought this happened on this line...:

Code: Select all

string luaCode = "return Variable[\"Day\"]";
...but I don't think so anymore. It must be from a previous line and it just takes some time to produce the exception. Maybe the previous line?

Code: Select all

Language.Lua.LuaInterpreter.Interpreter(s, tempLua);
It certainly looks like it's having a problem with that tempLua environment.

But to be honest, I'm at a complete loss with this because I'm not a proper coder, lol.

I'm also attaching a file with the s string value at runtime, in case it helps somehow. It's copied from VS2017 TXT visualizer, BEFORE it's further processed.

Thank you!
Attachments
s string.txt
(41.25 KiB) Downloaded 49 times
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Need to extract a variable value from savegame data string

Post by Abelius »

Also, and just for the record, I have this object on my scene...:

Image
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need to extract a variable value from savegame data string

Post by Tony Li »

Hi,

Change this line:

Code: Select all

Language.Lua.LuaInterpreter.Interpreter("Item = {}", tempLua);
to this:

Code: Select all

Language.Lua.LuaInterpreter.Interpreter("Item = {}; Conversation = {}", tempLua);
My test scene wasn't configured to save SimStatus, so I missed that before.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Need to extract a variable value from savegame data string

Post by Abelius »

Working! :D
Spoiler
Image
This will come in very handy. The alternative solution was to write separate PlayMaker variables in the save file, but that wasn't ideal at all.

Thank you for your help, as always! :mrgreen:
Unity 2019.4.9f1
Dialogue System 2.2.15
Post Reply