Page 1 of 1

How to change boolean variable at runtime through script?

Posted: Tue Apr 22, 2025 11:51 am
by SongsForgotten
Hello,

I'm currently implementing a mechanic where the player can choose a card from their collection during a conversation. This temporarily switches to a separate conversation, which immediately branches based on if the card played was right for the active dialogue node at the time. This is done by comparing two strings; the chosen card's name and a custom CardRequired field in the node. If the strings match, variable CorrectCardChosen should become true, which enables one dialogue link and disables another. If the strings don't match, the variable stays false and directs to another dialogue node.

My problem is that I'm unable to change the variable which does the branching at runtime. I attempted to change this via the code attached below, and can confirm via Variable Viewer that not changing the bool is where the process stops.

What might I be doing wrong?

Re: How to change boolean variable at runtime through script?

Posted: Tue Apr 22, 2025 12:38 pm
by Tony Li
Hi,

Consider the dialogue database to be static (read-only) at runtime.

The runtime variable values are in the Lua environment. Use the DialogueLua class to set the runtime value:

Code: Select all

DialogueLua.SetVariable("CorrectCardChosen", true);

Re: How to change boolean variable at runtime through script?

Posted: Wed Apr 23, 2025 3:59 am
by SongsForgotten
Hello Tony,

Thank you for the swift and clear response. This did just what I needed to. I've only been using the System for about a month now and haven't looked much into Lua yet. Clearly that's something I should do some reading on one of these days :)

Re: How to change boolean variable at runtime through script?

Posted: Wed Apr 23, 2025 7:58 am
by Tony Li
Glad to help! In general you don't need to look too deeply into Lua. You can use the C# methods such as DialogueLua.SetVariable(), and for dialogue entries' Conditions and Script fields you can use the "..." dropdown menus.