UI Bar connected to Variables

Announcements, support questions, and discussion for the Dialogue System.
Albyd
Posts: 29
Joined: Thu Jul 21, 2022 4:46 pm

Re: UI Bar connected to Variables

Post by Albyd »

It doesn't show and after interacting with an NPC who should increase the value, this is the error i'm getting:

InvalidCastException: Specified cast is not valid.
Confidence_bar.OnVariableChanged (System.String variableName, System.Object variableValue) (at Assets/Confidence_bar.cs:21)
Language.Lua.Assignment.SetKeyValue (Language.Lua.LuaValue baseValue, Language.Lua.LuaValue key, Language.Lua.LuaValue value) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/Chunk/Assignment.cs:133)
User avatar
Tony Li
Posts: 20993
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI Bar connected to Variables

Post by Tony Li »

Are you using the second version of the method with the Debug.Log line? It should show something. Since it reports line 21, I suspect it's not using the second version. Try this:

Code: Select all

void OnVariableChanged(string variableName, object variableValue)
{
    Debug.Log($"{variableName} changed to {variableValue}");
    if (variableName == "Confidence") scoreSlider.value = (float)((double)variableValue);
}
Post Reply