Page 1 of 1

Reset Variable to Initial value that is nil or ""

Posted: Wed Oct 07, 2015 1:09 pm
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

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

Posted: Wed Oct 07, 2015 2:40 pm
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);

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

Posted: Wed Oct 07, 2015 6:09 pm
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

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

Posted: Wed Oct 07, 2015 10:35 pm
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"] = ""

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

Posted: Thu Oct 08, 2015 1:08 pm
by nishant
Perfect thats exactly what was need .. thanks :)

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

Posted: Thu Oct 08, 2015 1:19 pm
by Tony Li
Great! Happy to help.