Script field And Varible Value

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Amine33
Posts: 22
Joined: Mon May 21, 2018 4:48 pm

Script field And Varible Value

Post 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...




User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Script field And Varible Value

Post 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()
Amine33
Posts: 22
Joined: Mon May 21, 2018 4:48 pm

Re: Script field And Varible Value

Post by Amine33 »

thank you very much .



He's working just like i want
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Script field And Varible Value

Post by Tony Li »

Great! Happy to help.
Amine33
Posts: 22
Joined: Mon May 21, 2018 4:48 pm

Re: Script field And Varible Value

Post by Amine33 »

Hi again

Is there a way I can Show Variable value in unity text UI..and not in Quest Tracker HUD :?:
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Script field And Varible Value

Post 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.
Post Reply