Page 2 of 2

Re: Create variables from script

Posted: Sun Mar 20, 2022 9:01 am
by Tony Li
Glad to help!

Re: Create variables from script

Posted: Sun Jul 17, 2022 10:34 am
by joeylu
Hi Tony, sorry I have to re-open this thread again, as I'm facing another variable issue with the database.
So continue from the previous discussion, as I'm using DialogueLua.SetVariable() to add/update variables in readonly master database, it's been working.
Until today that I'm adding a script in a dialogue entry, for example:

Code: Select all

Variable["test_variable"] += 1;
Notice that "test_variable" has never added to the database from dialogue editor, it is created and added in runtime from SetVariable(), I'm actually can get the "true" result by invoking DoesVariableExist("test_variable") after adding.

However, once that dialogue entry node is played, I'm getting a Null exception error, the only thing that I can guess is because this "test_variable" has never added from editor? does that mean SetVariable() adding new variables won't work with the entry node's script/condition setting?

tks

FYI, here's the error I'm getting
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.ConversationModel:GetState (PixelCrushers.DialogueSystem.DialogueEntry,bool,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:234)
PixelCrushers.DialogueSystem.ConversationModel:GetState (PixelCrushers.DialogueSystem.DialogueEntry) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:304)
PixelCrushers.DialogueSystem.ConversationController:OnSelectedResponse (object,PixelCrushers.DialogueSystem.SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:304)
PixelCrushers.DialogueSystem.ConversationView:SelectResponse (PixelCrushers.DialogueSystem.SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:504)
PixelCrushers.DialogueSystem.ConversationView:OnSelectedResponse (object,PixelCrushers.DialogueSystem.SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:497)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnClick (object) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:346)
PixelCrushers.DialogueSystem.StandardDialogueUI:OnClick (object) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardDialogueUI.cs:352)
PixelCrushers.DialogueSystem.StandardUIResponseButton:OnClick () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUIResponseButton.cs:132)

Re: Create variables from script

Posted: Sun Jul 17, 2022 12:44 pm
by Tony Li
That's a misleading error. The issue is that Lua doesn't have a "+=" operator. Use this instead:

Code: Select all

Variable["test_variable"] = Variable["test_variable"] + 1

Re: Create variables from script

Posted: Mon Jul 18, 2022 2:22 am
by joeylu
ahh, how stupid I am.. now it's working perfectly again !

Re: Create variables from script

Posted: Thu Jul 21, 2022 5:10 am
by joeylu
I'm also getting to a point to save variables by using PersistentDataManager
here's my steps
Using DialogueLua.SetVariable() to add variables that has generated from runtime
then PlayerPrefs.SetString(slotname, PersistentDataManager.GetSaveData()); to get all variables and save it to the playerPrefs

Somehow the result doesn't include variables that I have added from SetVariable(), only variables from the database. I must missed some steps, or PersistentDataManager.GetSaveData() is not something I should look for? tks

Re: Create variables from script

Posted: Thu Jul 21, 2022 8:41 am
by Tony Li
Hi,

PersistentDataManager.GetSaveData() will also save variables that you've created at runtime, such as through DialogueLua.SetVariable().

Examine the string returned by PersistentDataManager.GetSaveData(). Does it contain the variables? If so, then maybe the issue occurs when you're re-applying the save data. For example, maybe when you're loading a game you apply the save data (which restores the runtime variables) but then afterward call something like DialogueManager.ResetDatabase() which would reset the variables to their initial database state.

If the string doesn't contain the variables, double check that they exist at the time you call GetSaveData(). You can use the Dialogue Editor window's Watches tab > Menu > Add All Runtime Variables to see a list of them. Or you can add a Lua Console to your scene, press ~+L to open it during play, and enter "return Variable" to see the list.

Re: Create variables from script

Posted: Sun Jul 24, 2022 4:57 am
by joeylu
tks, indeed there's ResetDatabase was called and removing it solves the issue

Re: Create variables from script

Posted: Sun Jul 24, 2022 8:34 am
by Tony Li
Glad you got to the bottom of it!