Assigned variables are show up as nil in Dialogue Text

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

Assigned variables are show up as nil in Dialogue Text

Post by rakkar »

I want to display the result of a function call in Dialogue Text. (see screenshot)
Capture.PNG
Capture.PNG (37.15 KiB) Viewed 863 times
However, the variable is substituted with "nil" rather than what I assigned in the script block.

If I open the Lua Console and call the function it shows the correct value in the console
print( GetFriendlyCompositionAccurate());

If, in the Lua console I assign the result of the function to the variable, then print it, it is also correct
Variable["CapitalDefense_FriendlyCompositionAccurate"]=GetFriendlyCompositionAccurate();
print(Variable["CapitalDefense_FriendlyCompositionAccurate"]);

I had the same script code earlier as well, using a dummy node with Sequence None() but the result was the same.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by Tony Li »

That should work. Conversations run their Script fields before processing Dialogue Text. Are there any errors or warnings in the Console when the conversation gets to that dialogue entry?

As a test, would you please try using the [lua(code)] tag instead of [var=variable]?

Code: Select all

You city is under siege. Your scouts estimate [lua(GetEnemyCompositionInaccurate())].
Your army is composed of [lua(GetFriendlyCompositionAccurate())]
Please feel free to send a reproduction project to tony (at) pixelcrushers.com if you can't get to the bottom of it.
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by rakkar »

" Conversations run their Script fields before processing Dialogue Text. "

This isn't the case in my version, and I actually tested it through the debugger because I wasn't sure if I needed an extra node to process the script when the user selected an option. For example, I want to run a script when the user presses easy, medium, or hard. The dialogue text "Easy", "Medium" and "Hard" shows up as conversation response options, yet the script does not run until the user actually presses the button.

This is actually what I want, but just pointing out maybe there's a bug in my version.

Using 2.2.4
Attachments
Capture.PNG
Capture.PNG (75.04 KiB) Viewed 854 times
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by Tony Li »

We were talking about different things. When the Dialogue System shows a subtitle (i.e., in the subtitle panel), it runs the Script first, then it parses any markup tags in the Dialogue Text and displays it.

When showing a player response menu, it doesn't run the Script until after the player has clicked on a response button.
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by rakkar »

[lua(Variable["..."])] works, var= does not

My game is huge, it would take me hours to try to make a repro case and no guarantee I can do so. But if you can point me where in the code to look I can possibly debug it myself.
Attachments
Capture2.PNG
Capture2.PNG (219.52 KiB) Viewed 853 times
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by Tony Li »

No quotes around variable names. Use [var=CapitalDefense_ScoutingCost].
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by rakkar »

Thank you. Is there a built-in way to round off numeric variables , so I don't show 150.82 gold?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assigned variables are show up as nil in Dialogue Text

Post by Tony Li »

Yes, if you use the [lua(code)] tag, such as:
  • Dialogue Text: [lua(math.floor(Variable["CapitalDefense_ScoutingCost"]))] Hire a rogue

If you set Variable["CapitalDefense_ScoutingCost"] to an integer value, then you can use [var=CapitalDefense_ScoutingCost]:
  • Script: Variable["CapitalDefense_ScoutingCost"] = math.floor(150.82)
Post Reply