Reset Variable to Initial value that is nil or ""

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
nishant
Posts: 55
Joined: Mon Sep 21, 2015 3:16 pm
Location: Canada
Contact:

Reset Variable to Initial value that is nil or ""

Post by nishant »

Hi,
Is there anyway to reset a variable to its initial value ? Initial value for my variable is "" and I am not able to set that variable again

Thanks.
Nishant
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reset Variable to Initial value that is nil or ""

Post by Tony Li »

Hi,

Can you just set it to "" in a dialogue entry's Script field?
  • Script: Variable["MyVariable"] = ""
Or, in a script:

Code: Select all

DialogueLua.SetVariable("MyVariable", string.Empty);
If you don't know the initial value, you can get it from the dialogue database:

Code: Select all

var initialValue = DialogueManager.MasterDatabase.GetVariable("MyVariable").InitialValue;
DialogueLua.SetVariable("MyVariable", initialValue);
nishant
Posts: 55
Joined: Mon Sep 21, 2015 3:16 pm
Location: Canada
Contact:

Re: Reset Variable to Initial value that is nil or ""

Post by nishant »

Ok I did that , but there seems to another issue
The sequence of nodes is as follows

1. "Whats your name " - has condition display textbox only if PlayerName is "" which is the initial value and False condition is PassThrough
2. "Is your name [enteredName] " - it is followed by yes and no options
3. yes - moves on to next dialogue
4. no - resets the name and moves to 1st link

So Issue is name does reset but by the time I reach to node 1 , it seems the change isnt reflected while evaluating the condition. So as condition is termed as false , it passes that node and moves to node 2. Here we get "Is your name " as dialogue text . No if I again click No that time Textbox will appear.

How can I fix this ??

Thanks.
Nishant
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reset Variable to Initial value that is nil or ""

Post by Tony Li »

Hi Nishant,

Check this example: Nishant_2015-10-07.unitypackage

Add a "spacer" node. The Dialogue System always evaluates one level ahead. This allows it to know what the follow-up nodes are. It needs to know this to know whether to play another NPC line or show the response menu. In the screenshot below, the spacer node is called "(empty hub)":

Image

The "(empty hub)" node's Sequence is: None() so it immediately evaluates it and moves to the next step in the conversation. The spacer node delays evaluation of the "What's your name?" node.

If the player answers "No," the response's Script resets the PlayerName variable, and the node links back to the top.
  • Script:Variable["PlayerName"] = ""
nishant
Posts: 55
Joined: Mon Sep 21, 2015 3:16 pm
Location: Canada
Contact:

Re: Reset Variable to Initial value that is nil or ""

Post by nishant »

Perfect thats exactly what was need .. thanks :)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reset Variable to Initial value that is nil or ""

Post by Tony Li »

Great! Happy to help.
Post Reply