[lua(
if (Variable["number_of_pirates"] > 1)
then
"there are " .. Variable["number_of_pirates"] .. " more pirates left"
else
"there is one more pirate left"
end
)]
In theory this code must generate phrase like: "there are 2 more pirates left"
I wrote it in one line
But I get nil instead.
And no errors or warnings in console
P.S.
I know that I can use 2 nodes with appropriate conditions instead, but what if it will be more complicated logic?
Your [lua(code)] should return a value. You could write it as a function, or use the built-in Conditional() function. Conditional() takes two string parameters: a condition and the text to show if the condition is true. So you could do something like:
[lua(Conditional("Variable['number_of_pirates'] > 1", "there are [var=number_of_pirates] more pirates left"))]
[lua(Conditional("Variable['number_of_pirates'] == 1", "there is one more pirate left"))]
Or you could Lua's ternary operator syntax: "condition and true-value or false-value which is more compact":