Hey Tony. I'm trying to combine multiple variables to make the text display a single sentence to describe a character, something like this:
"Jack, 19, carpenter"
To achieve this, I'm referencing 3 variables: CHR_Name, CHR_Age, CHR_Occupation. I also have another variable that is supposed to include all of this which is CHR_Description.
In the script field, I have the following:
Variable["CHRDescription"] = "[var=CHR_Name], [var=CHR_Age], [CHR_Occupation]";
However, instead of showing up as the correct text, it's just showing up as that line of script.
I feel like I've done something like this before but don't remember exactly how, maybe this way isn't possible.
Combining variables as text
Re: Combining variables as text
Hi,
The [var=variable] tag is for text fields, but the Script field is a Lua code field. Use this instead:
The [var=variable] tag is for text fields, but the Script field is a Lua code field. Use this instead:
Code: Select all
Variable["CHRDescription"] = Variable["CHR_Name"] .. ", " .. Variable["CHR_Age"] .. ", " .. Variable["CHR_Occupation"]
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Combining variables as text
Thanks Tony, that makes sense.
It's displaying correctly now, but I'm having trouble getting it to change visually if the variable changes. If I change one of the variables in the Script field, for example set CHR_Age to 20, it still displays 19 in the on screen text field.
This is the script I'm using to display variables on screen, I think it's one you gave me a while ago
Thanks for your help as always.
It's displaying correctly now, but I'm having trouble getting it to change visually if the variable changes. If I change one of the variables in the Script field, for example set CHR_Age to 20, it still displays 19 in the on screen text field.
This is the script I'm using to display variables on screen, I think it's one you gave me a while ago
Thanks for your help as always.
Code: Select all
using UnityEngine;
using TMPro;
using PixelCrushers.DialogueSystem;
public class ShowVariableText : MonoBehaviour // Add this script to a TextMeshProUGUI GameObject.
{
[VariablePopup] public string variableName;
private void Update()
{
GetComponent<TextMeshProUGUI>().text = DialogueLua.GetVariable(variableName).asString;
}
}
Re: Combining variables as text
Hi,
Use this version instead:
You'll need to be using DS version 2.2.44 or newer.
Use this version instead:
Code: Select all
using UnityEngine;
using TMPro;
using PixelCrushers.DialogueSystem;
public class ShowVariableText : MonoBehaviour // Add this script to a TextMeshProUGUI GameObject.
{
[VariablePopup] public string variableName;
private void Start()
{
Language.Lua.Assignment.MonitoredVariables.Add(variableName);
Language.Lua.Assignment.VariableChanged += OnVariableChanged;
UpdateText();
}
private void OnDestroy()
{
Language.Lua.Assignment.VariableChanged -= OnVariableChanged;
}
private void OnVariableChanged(string variableName, object value)
{
UpdateText();
}
private void UpdateText()
{
GetComponent<TextMeshProUGUI>().text = DialogueLua.GetVariable(variableName).asString;
}
}
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Combining variables as text
Working perfectly now, thanks so much!
Re: Combining variables as text
Happy to help!