Page 1 of 2

Show Lua variable on screen with UI Textmeshpro

Posted: Thu Mar 21, 2024 5:29 pm
by Dumppermen10
Hello.

I'm trying to put my Dialogue Manager variables on the UI screen with Textmeshpro.

But everything I do never works
Would appreciate any feedback on how to get this to work. Thanks.

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Fri Mar 22, 2024 12:28 am
by Tony Li
Hi,

Try:

Code: Select all

CoinText.text = FormattedText.ParseCode("[var=Coin]");

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Fri Mar 22, 2024 4:27 am
by Dumppermen10
I posted that line in (void Update()). And it worked great.
Thank you very much. You saved me a ton of headache.

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Fri Mar 22, 2024 11:46 am
by Tony Li
Glad to help!

Tip: If you want to optimize, instead of using Update() monitor the variable for changes: Monitor Variable Value Changes

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sat Mar 23, 2024 1:44 am
by Dumppermen10
Thanks, your the best.

Also, is it possible to do (If Statements) with the lua variables in C# Script?

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sat Mar 23, 2024 11:09 am
by Tony Li
Hi,

Yes. In C#:

Code: Select all

if (DialogueLua.GetVariable("Coin").asInt > 50)
{
    CommentText.text = "Wow, you're rich!";
}
In Lua Conditions:
  • Conditions: Variable["Coin"] < 50
  • Dialogue Text: "Sorry, you don't have enough coin to purchase that."
You can also use it conditionally in-line in text using [lua(code)] and the Conditional function. If you need to do that, let me know and I'll add an example.

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sat Mar 23, 2024 3:13 pm
by Dumppermen10
I keep getting an error when I type that line of code in?

Operator '>' cannot be applied to operands of type 'Lua.Result' and 'into.

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sat Mar 23, 2024 4:02 pm
by Dumppermen10
Also I'll take an example of the in-line conditionals as well.

For future references.
😁

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sat Mar 23, 2024 5:05 pm
by Tony Li
Sorry, I fixed the typo above. I had forgotten to type ".asInt" at the end.

Please see the Conditional() function for an example of in-line.

Re: Show Lua variable on screen with UI Textmeshpro

Posted: Sun Mar 24, 2024 1:01 am
by Dumppermen10
Awesome! It worked. Thanks man.
Without your help I would seriously be lost. 😂😂😂