Page 1 of 1
Get all variables that contain "specific_string"
Posted: Sun Feb 02, 2025 6:33 am
by lemonjolly_anna
Hello!
Is there a way to DialogueLua.
GetVariable any variables that contain
"specific_string"?
Use Case:
- have int variables named "visits.thisrun.etc"
Cheers!
Re: Get all variables that contain "specific_string"
Posted: Sun Feb 02, 2025 10:37 am
by Tony Li
Hi,
It's easiest if your variables are defined in your dialogue database (i.e., at design time, not newly-added at runtime). Loop through the variables list:
Code: Select all
foreach (var variable in DialogueManager.masterDatabase.variables)
{
if (variable.Name.Contains("visits.thisrun"))
{
Debug.Log($"Found {variable.Name}: {DialogueLua.GetVariable(variable.Name).asInt}");
}
}
If the variables are created at runtime, you'll need to loop through the Lua table:
Code: Select all
var variables = Lua.Run("return Variable").asTable;
foreach (var variableName in variables.Keys)
{
if (variableName.Contains("visits.thisrun"))
{
Debug.Log($"Found {variableName}: {DialogueLua.GetVariable(variableName).asInt}");
}
}