Show Lua variable on screen with UI Textmeshpro

Announcements, support questions, and discussion for the Dialogue System.
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Show Lua variable on screen with UI Textmeshpro

Post 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.
Attachments
My C# script
My C# script
20240321_172259 (1).jpg (945.42 KiB) Viewed 549 times
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post by Tony Li »

Hi,

Try:

Code: Select all

CoinText.text = FormattedText.ParseCode("[var=Coin]");
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post by Dumppermen10 »

I posted that line in (void Update()). And it worked great.
Thank you very much. You saved me a ton of headache.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post 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
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post by Dumppermen10 »

Thanks, your the best.

Also, is it possible to do (If Statements) with the lua variables in C# Script?
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post 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.
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post 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.
Attachments
20240323_145111 (1) (1).jpg
20240323_145111 (1) (1).jpg (900.66 KiB) Viewed 493 times
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post by Dumppermen10 »

Also I'll take an example of the in-line conditionals as well.

For future references.
😁
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post 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.
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: Show Lua variable on screen with UI Textmeshpro

Post by Dumppermen10 »

Awesome! It worked. Thanks man.
Without your help I would seriously be lost. 😂😂😂
Post Reply