Variables not setting!

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
EdwinWiseOne
Posts: 7
Joined: Tue Mar 08, 2022 6:36 pm

Variables not setting!

Post by EdwinWiseOne »

This seems like an absurdly basic and simple task, and yet it doesn't seem to be working for me.

I have a simple conversation that, near the end, it sets a boolean value:

Variable editor:

Code: Select all

IntroductionComplete, initial value=false, Boolean
Conversation node Sequence:

Code: Select all

SetVariable(IntroductionComplete, true);
Then, in C# code, after the conversation is completed, I check the value of that boolean:

C# Query Code:

Code: Select all

string savedVariables = PersistentDataManager.GetSaveData();
Which gives me...

C# Query result:

Code: Select all

03-08 17:34:02.464 24350 24373 I Unity   : ### Variable={Alert="", IntroductionComplete=false}; ...
What am I missing?

I got to this point because the save system didn't seem to be working, but it seems that the VARIABLE system is not working. At least, I don't see changed values outside of the conversation.

If I set the variable inside the conversation and then use it as a condition within the conversation, it works fine. But I'm trying to store the conversation state so the next time it comes up, it behaves differently than the first time.


Edwin!
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variables not setting!

Post by Tony Li »

Hi Edwin,

Are there any errors or warnings in the Console window?

For what you want to accomplish, this page may help: How To: Run a Conversation Only Once. (Includes how to run a different conversation the second time.)

That page shows how to set the variable using the Script field instead of the Sequence field. Either way is fine, but you might prefer the Script field because it does more syntax error checking. Also, you can build the Script field value using the "..." dropdown menus instead of having to type it manually, which helps avoid typos.

Can you try this C# query code?

Code: Select all

bool introComplete = DialogueLua.GetVariable("IntroductionComplete").asBool;
Debug.Log($"IntroductionComplete = {introComplete}");
// string savedVariables = PersistentDataManager.GetSaveData();
If that also doesn't work, then is it possible that something at the end of the conversation (maybe a script set to OnConversationEnd) is resetting the variables?
EdwinWiseOne
Posts: 7
Joined: Tue Mar 08, 2022 6:36 pm

Re: Variables not setting!

Post by EdwinWiseOne »

Thank you for your prompt response.

It turns out that I had attached my script that checked the value to the wrong thing! Entirely pilot error...

Once things are run in the correct order, it works much better.

Edwin!
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variables not setting!

Post by Tony Li »

Glad to help!

Another tip is to watch the variable's value in the Dialogue Editor's Watches tab. You can set it to auto-refresh the display at a specified frequency, which can give you a better idea of when variables change values while you're playing.
Post Reply