Hi,
In Dialogue Text and quest entry text, you can use the [var=
variable] tag to show the value of a single variable, or the [lua(
code)] tag to show the result of a Lua expression.
One solution is to register a C# method with Lua. That C# method could check the variable value and return an appropriate string. For example, say you register a C# method called GetFeeling(x):
Code: Select all
string GetFeeling(double x) // (C# methods that talk to Lua should use doubles for numbers)
{
if (x <= 50) return "hated";
else if (x >= 75) return "loved";
else return "liked";
}
Then you can use that in your Dialogue Text:
- Dialogue Text: Relationship: [lua(GetFeeling("Variable["Charactername_Points"]))]
---
Alternatively, you could skip all that and use this obscure bit of Lua syntax that we'll call a "ternary":
condition and
true-value or
false-value
For example, say a variable x is set to a random value 1-100. (Note that, to keep the code shorter and easier to read, I'm using a local Lua variable x and not a Lua variable in the Dialogue System table Variable["x"].) If x is less than 50, you want to return the string "heads". Otherwise return the string "tails". To do that, use this syntax:
You can nest one ternary inside another like this:
condition1 and
condition-1-true-value or (
condition2 and
condition-2-true-value or
condition-2-false-value )
For example, let's say you want to return hated, liked, or loved based on the value of x:
- hated: x <= 50
- loved: x >= 75
- liked: 51 <= x < 75
The expression could look like this:
Code: Select all
(x <= 50) and "hated" or ((x >= 75) and "loved" or "liked")
To use your Variable["Charactername_Points"] variable instead of x, it looks like:
Code: Select all
(Variable["Charactername_Points"] <= 50) and "hated" or ((Variable["Charactername_Points"] >= 75) and "loved" or "liked")
Here's an example:
- Dialogue Text: Relationship: [lua((Variable["Charactername_Points"] <= 50) and "hated" or ((Variable["Charactername_Points"] >= 75) and "loved" or "liked"))]