Communicating with a variable created on dialogue script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Noodle_Soup
Posts: 12
Joined: Mon Nov 20, 2017 11:38 pm

Communicating with a variable created on dialogue script

Post by Noodle_Soup »

Hi,

I've just tried this on certain dialogue script:

Code: Select all

Variable["spokeToKing"] = false;
Just in case, spokeToKing doesn't exist within my Database Variables, thing is, I tried to retrieve that variable from a script later on by doing this (so I could change it from false to true by pressing a button during the conversation (not the dialogue buttons by the way) and then proceed to two possible outcomes depending on the bool value):

Code: Select all

bool spokeToKing = DialogueLua.GetVariable("spokeToKing").AsBool;
DialogueLua.SetVariable("spokeToKing", true);
Not working. Creating the variable works, but trying to retrieve it and then send it back, no luck so far, still checking the forums though.

Thanks for taking your time with this. :)
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Communicating with a variable created on dialogue script

Post by Tony Li »

Hi,

That code should work. It's possible that the issue is that Conversations Evaluate Conditions One Extra Level Ahead.

If you call DialogueLua.GetVariable("spokeToKing").AsBool and "spokeToKing" isn't defined yet, it will return false.

If you call DialogueLua.SetVariable("spokeToKing", true) and "spokeToKing" isn't defined yet, it will define it. You don't need to declare it ahead of time. The variable will also be included in saved games, even if it wasn't originally in the database.

You may find the Lua Console helpful, or the Dialogue Editor's Watches tab.

Note that if a variable isn't defined yet, then in Lua its value will be nil. If you use the condition below in a dialogue entry's Conditions field and "spokeToKing" isn't defined yet, it will return false:

Code: Select all

Variable["spokeToKing"] == false
This is because, in Lua, Variable["spokeToKing"] is equal to nil, not false, until you define it. There are three ways to define it:
  • Assign it in Lua: Variable["spokeToKing"] = false
  • In C#: DialogueLua.SetVariable("spokeToKing", false);
  • Or define it in your dialogue database in the Dialogue Editor.
And you're always welcome to send an example scene to tony (at) pixelcrushers.com. I'll be happy to take a look.
Noodle_Soup
Posts: 12
Joined: Mon Nov 20, 2017 11:38 pm

Re: Communicating with a variable created on dialogue script

Post by Noodle_Soup »

Tony Li wrote: Wed Oct 24, 2018 10:33 am Hi,

That code should work. It's possible that the issue is that Conversations Evaluate Conditions One Extra Level Ahead.

If you call DialogueLua.GetVariable("spokeToKing").AsBool and "spokeToKing" isn't defined yet, it will return false.

If you call DialogueLua.SetVariable("spokeToKing", true) and "spokeToKing" isn't defined yet, it will define it. You don't need to declare it ahead of time. The variable will also be included in saved games, even if it wasn't originally in the database.

You may find the Lua Console helpful, or the Dialogue Editor's Watches tab.

Note that if a variable isn't defined yet, then in Lua its value will be nil. If you use the condition below in a dialogue entry's Conditions field and "spokeToKing" isn't defined yet, it will return false:

Code: Select all

Variable["spokeToKing"] == false
This is because, in Lua, Variable["spokeToKing"] is equal to nil, not false, until you define it. There are three ways to define it:
  • Assign it in Lua: Variable["spokeToKing"] = false
  • In C#: DialogueLua.SetVariable("spokeToKing", false);
  • Or define it in your dialogue database in the Dialogue Editor.
And you're always welcome to send an example scene to tony (at) pixelcrushers.com. I'll be happy to take a look.
Thanks a lot, Tony.

I removed the first entry from the dialogue script and now only check for true or false, defining it on the spot is quite convenient for what I need, had some little issues after that, but then I added another node with None() for evaluation delaying, just like in that link you showed me, and now it works like a charm, again, thanks a lot dude. :)
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Communicating with a variable created on dialogue script

Post by Tony Li »

Glad to help!
Post Reply