Page 1 of 1

Communicating with a variable created on dialogue script

Posted: Wed Oct 24, 2018 10:23 am
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. :)

Re: Communicating with a variable created on dialogue script

Posted: Wed Oct 24, 2018 10:33 am
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.

Re: Communicating with a variable created on dialogue script

Posted: Wed Oct 24, 2018 11:20 am
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. :)

Re: Communicating with a variable created on dialogue script

Posted: Wed Oct 24, 2018 11:23 am
by Tony Li
Glad to help!