Lua code error on ApplySaveData

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
dmcrider
Posts: 1
Joined: Mon Nov 01, 2021 3:21 pm

Lua code error on ApplySaveData

Post by dmcrider »

I have some data that I gather in a custom Saver. On the pause screen UI, there's a Save Game button that calls this custom Saver. After I gather the necessary data, I call

Code: Select all

PersistentDataManager.ApplySaveData(gameData)
This, however, throws a Lua code error:

Code: Select all

Dialogue System: Lua code '{"PlayerPosition":"-6.147034,0.1742856,-14.47527,0,-0.1305264,0,-0.9914448","PlayerData":"0,Terithan,20,20,10,10,1,0","PlayerInventory":"25|0,Mom's Elixer,A family secret,20,False,True,False,5,1,Consumable|1,Whitling Knife,A small knife used for carving.,2,False,True,False,1,1,Weapon","NPCPositions":"6.89727,0.1276187,-13.23673,0,0.4483954,0,0.8938354|-13.38935,0.1276187,9.430729,0,0.2463654,0,0.9691771","NPCData":"1,Elaine,35,35,15,15,5,2510|0,Humfort,30,30,10,10,5,2500"}' threw exception 'Code has syntax errors:
Line 1, Col 1 '{': Failed to parse Letter of Name.
Line 1, Col 1 '{': Failed to parse Name of VarName.
Line 1, Col 1 '{': Failed to parse 'nil' of NilLiteral.
Line 1, Col 1 '{': Failed to parse Text of BoolLiteral.
Line 1, Col 1 '{': Failed to parse '0'...'9' of Digit.
Line 1, Col 1 '{': Failed to parse (Digit)+ of FloatNumber.
Line 1, Col 18 ':': Failed to parse '}' of TableConstructor.
Line 1, Col 1 '{': Failed to parse Name of VariableArg.
Line 1, Col 1 '{': Failed to parse firstTerm of OperatorExpr.
Line 1, Col 1 '{': Failed to parse Expr of ExprStmt.
Line 1, Col 1 '{': Failed to parse remaining input.
'
UnityEngine.Debug:LogError (object)
PixelCrushers.DialogueSystem.Lua:RunRaw (string,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:228)
PixelCrushers.DialogueSystem.Lua:Run (string,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:129)
PixelCrushers.DialogueSystem.Lua:Run (string,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
PixelCrushers.DialogueSystem.PersistentDataManager:ApplyLuaInternal (string,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:261)
PixelCrushers.DialogueSystem.PersistentDataManager:ApplySaveData (string,PixelCrushers.DialogueSystem.DatabaseResetOptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:246)
Anagorth.AnagorthSaver:SaveGame () (at Assets/Scripts/Utility/AnagorthSaver.cs:32)
Does my JSON include bad characters? I've been writing C# code for almost a decade now, but I have no experience with Lua, so I'm not sure where I'm going wrong here. Is my whole implementation bad?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua code error on ApplySaveData

Post by Tony Li »

Hi,

Saver components use the Save System. You don't need to call PersistentDataManager. Call these methods instead:

Code: Select all

PixelCrushers.SaveSystem.SaveToSlot(#);
...
PixelCrushers.SaveSystem.LoadFromSlot(#);
API Reference: SaveSystem

This is the flowchart that's at the bottom of the Save System manual page:

Image

PersistentDataManager sits between "Dialogue System data" and "Dialogue System Saver". Dialogue System Saver uses PersistentDataManager to save and record the Dialogue System's internal data (variables, quest states, etc.).

Your own savers ("Other savers..." in the flowchart) don't need to worry about PersistentDataManager.

If you have any questions about this, just let me know.
Post Reply