I want to display the result of a function call in Dialogue Text. (see screenshot)
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.
Assigned variables are show up as nil in Dialogue Text
Re: Assigned variables are show up as nil in Dialogue Text
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]?
Please feel free to send a reproduction project to tony (at) pixelcrushers.com if you can't get to the bottom of it.
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())]
Re: Assigned variables are show up as nil in Dialogue Text
" 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
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 (75.04 KiB) Viewed 848 times
Re: Assigned variables are show up as nil in Dialogue Text
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.
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
[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.
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 (219.52 KiB) Viewed 847 times
Re: Assigned variables are show up as nil in Dialogue Text
No quotes around variable names. Use [var=CapitalDefense_ScoutingCost].
Re: Assigned variables are show up as nil in Dialogue Text
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
Yes, if you use the [lua(code)] tag, such as:
If you set Variable["CapitalDefense_ScoutingCost"] to an integer value, then you can use [var=CapitalDefense_ScoutingCost]:
- 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)