Page 1 of 1

Script field And Varible Value

Posted: Thu Jul 25, 2019 6:24 pm
by Amine33
Thanks Very Much For you Answer in private
can you please tell me how to use Script field for change a variable value...





Re: Script field And Varible Value

Posted: Thu Jul 25, 2019 7:20 pm
by Tony Li
Hi,

Let's say you have a variable named "Dollars".

To create this variable, open your dialogue database in the Dialogue Editor. Go to the Variables section. Click the "+" button and select Number. Name the variable "Dollars". You can set an initial value such as 30.

If you want to give the player 10 dollars in a dialogue entry, click the "..." next to the Script field. Then click "+". From the dropdowns, select Variable > Dollars > Add > 10. Then click Apply. Your dialogue entry might then have fields like this:
  • Dialogue Text: [Player] "Give me $10."
  • Script:

    Code: Select all

    Variable["Dollars"] = Variable["Dollars"] + 10
If you want to show this in a HUD, go to the Quest section and add a new quest. Tick Use Display Name. Set Display Name to: "You have $[var=Dollars]". Set the State to active.

Then go back to your dialogue entry, and add a line to the Script field:
  • Dialogue Text: [Player] "Give me $10."
  • Script:

    Code: Select all

    Variable["Dollars"] = Variable["Dollars"] + 10;
    UpdateTracker()

Re: Script field And Varible Value

Posted: Thu Jul 25, 2019 8:19 pm
by Amine33
thank you very much .



He's working just like i want

Re: Script field And Varible Value

Posted: Thu Jul 25, 2019 8:48 pm
by Tony Li
Great! Happy to help.

Re: Script field And Varible Value

Posted: Sat Jul 27, 2019 7:42 pm
by Amine33
Hi again

Is there a way I can Show Variable value in unity text UI..and not in Quest Tracker HUD :?:

Re: Script field And Varible Value

Posted: Sun Jul 28, 2019 2:01 am
by Tony Li
Yes. When you assign a string to a Text component, run it through FormattedText.ParseCode first.

Instead of this:

Code: Select all

public UnityEngine.UI.Text myText;
...
myText.text = "You have $[var=Dollars]";
use this:

Code: Select all

myText.text = FormattedText.ParseCode("You have $[var=Dollars]");
This will replace all [var=variable] and [lua(code)] tags with their current values.