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:
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.