Create variables from script
Re: Create variables from script
Glad to help!
Re: Create variables from script
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:
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)
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;
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
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
ahh, how stupid I am.. now it's working perfectly again !
Re: Create variables from script
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
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
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.
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
tks, indeed there's ResetDatabase was called and removing it solves the issue
Re: Create variables from script
Glad you got to the bottom of it!