Page 1 of 2

Need to extract a variable value from savegame data string

Posted: Fri Dec 03, 2021 3:47 pm
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?

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

Posted: Fri Dec 03, 2021 4:27 pm
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();

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

Posted: Fri Dec 03, 2021 6:14 pm
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.

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

Posted: Fri Dec 03, 2021 6:49 pm
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();

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

Posted: Fri Dec 03, 2021 8:14 pm
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:

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

Posted: Fri Dec 03, 2021 8:55 pm
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();
        }
    }
}

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

Posted: Sat Dec 04, 2021 6:40 am
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!

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

Posted: Sat Dec 04, 2021 6:55 am
by Abelius
Also, and just for the record, I have this object on my scene...:

Image

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

Posted: Sat Dec 04, 2021 9:01 am
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.

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

Posted: Sat Dec 04, 2021 10:21 am
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: