Conversation Variables won't update
Posted: Wed Apr 02, 2025 11:35 pm
This is my first time working with the Dialogue System and I have been having some issues, finding the documentation hard to navigate so I am really at a loss.
I am basically trying to make a job aptitude quiz for a VR game and I can't seem to get the Lua function to register correctly. I've got it to work for other variables just fine but it just wont work, I've tested the code with taking only one variable instead of two and the problem persists! Any help would be greatly appreciated.
this is my code
and this is the error I am getting consistently
I am basically trying to make a job aptitude quiz for a VR game and I can't seem to get the Lua function to register correctly. I've got it to work for other variables just fine but it just wont work, I've tested the code with taking only one variable instead of two and the problem persists! Any help would be greatly appreciated.
this is my code
Code: Select all
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class JobSelector : MonoBehaviour
{
private Dictionary<string, float> jobScores = new Dictionary<string, float>()
{
{ "Leader", 0 },
{ "Explorer", 0 },
{ "Midwife", 0 },
{ "Machinist", 0 },
{ "Farmer", 0 },
{ "Helper", 0 }
};
public string bestJob;
public string worstJob;
public float highScore;
public float lowScore;
void OnEnable()
{
Lua.RegisterFunction("UpdateJobScore", this, SymbolExtensions.GetMethodInfo(() => UpdateJobScore(string.Empty, (double)0)));
}
void OnDisable()
{
Lua.UnregisterFunction("UpdateJobScore");
}
public void ResetScores()
{
foreach (var key in jobScores.Keys)
{
jobScores[key] = 0;
}
highScore = 0;
lowScore = 0;
bestJob = "";
worstJob = "";
}
public void UpdateJobScore(string job, double amount)
{
float score = (float)amount;
if (jobScores.ContainsKey(job))
{
jobScores[job] += (float)score;
CalculateScores();
}
else
{
Debug.LogError("Invalid job name: " + job);
}
}
private void CalculateScores()
{
highScore = float.MinValue;
lowScore = float.MaxValue;
foreach (var job in jobScores)
{
if (job.Value > highScore)
{
highScore = job.Value;
bestJob = job.Key;
}
if (job.Value < lowScore)
{
lowScore = job.Value;
worstJob = job.Key;
}
}
// Store best & worst job in Dialogue System
DialogueLua.SetVariable("BestJob", bestJob);
DialogueLua.SetVariable("WorstJob", worstJob);
}
}
Lua code 'UpdateJobScore("Explorer", 2)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
UnityEngine.Debug:LogError (object)
PixelCrushers.DialogueSystem.Lua:RunRaw (string,bool,bool) .... etc a bunch of file locactions that make this post look like spam