Page 1 of 1

Assigned variables are show up as nil in Dialogue Text

Posted: Mon Jan 13, 2020 10:45 pm
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 858 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.

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

Posted: Tue Jan 14, 2020 9:11 am
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.

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

Posted: Thu Jan 16, 2020 1:26 pm
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

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

Posted: Thu Jan 16, 2020 1:40 pm
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.

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

Posted: Thu Jan 16, 2020 1:43 pm
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.

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

Posted: Thu Jan 16, 2020 2:29 pm
by Tony Li
No quotes around variable names. Use [var=CapitalDefense_ScoutingCost].

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

Posted: Fri Jan 17, 2020 10:49 am
by rakkar
Thank you. Is there a built-in way to round off numeric variables , so I don't show 150.82 gold?

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

Posted: Fri Jan 17, 2020 11:28 am
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)