Page 1 of 1

Set variable.

Posted: Thu Sep 17, 2020 12:56 pm
by megadok
Hey Tony!

I would like to know how I can change the value of a variable in my database.

I have tried...

Code: Select all

myDatabase.variables[0].InitialValue = "megadok";
It work.

But i need something like this...

Code: Select all

myDatabase.setVariable("variableName")="anything";
Thank you!

Re: Set variable.

Posted: Thu Sep 17, 2020 1:07 pm
by Tony Li
Hi,

At runtime, variable values are stored in Lua. Use the DialogueLua class to get and set variables:

Code: Select all

DialogueLua.SetVariable("X", 42);
Debug.Log("X is " + DialogueLua.GetVariable("X").asInt);

Re: Set variable.

Posted: Thu Sep 17, 2020 1:46 pm
by megadok
I did:

Code: Select all

PixelCrushers.DialogueSystem.DialogueLua.SetVariable("Alert","anything");

Code: Select all

 Debug.Log("Your word is " + PixelCrushers.DialogueSystem.DialogueLua.GetVariable("Alert").ToString());
Console said me:

Code: Select all

Your word is  PixelCrushers.DialogueSystem.Lua+Result  
:|

What is the problem?

Thanks!

Re: Set variable.

Posted: Thu Sep 17, 2020 1:49 pm
by megadok
Ok I solved it this way...

Code: Select all

Debug.Log("X is " + PixelCrushers.DialogueSystem.DialogueLua.GetVariable("Alert").luaValue.ToString());
Thank you Tony!

Re: Set variable.

Posted: Thu Sep 17, 2020 2:08 pm
by Tony Li
That will work. A shortcut is:

Code: Select all

Debug.Log("X is " + PixelCrushers.DialogueSystem.DialogueLua.GetVariable("Alert").asString);