Page 1 of 1

Using DS variables in c#

Posted: Tue Feb 11, 2025 11:18 am
by thatisfreakinggreat
Hi,
This is kinda driving me a bit mad! I've combed through google and here, haven't seen anything yet so i am reaching out for help.
I have a delagate and event system for my XP in my 2d Game. I am using DS for dialogue and quest system, but the problem I am having is that i can not seem to get my DS XP var to add onto the c# script XP.

I did this
private int expAmount, cacheXp;

// Start is called before the first frame update
void Start()
{
cacheXp = expAmount;
}

// Update is called once per frame
void Update()
{
int xpValue = DialogueLua.GetVariable("XPValue").asInt;
expAmount = xpValue;
if (expAmount > cacheXp)
{
CheckXp();
cacheXp = expAmount;
}
}

private void CheckXp()
{
Debug.Log("CheckXp = " + expAmount);
ExperienceManager.Instance.AddExperience(expAmount);
}
It kinda works. It updates my players XP,
but when I go to another xp provider in my game, it doesn't do anything other than show the value of the new xpgiver.

Any help or advice would be appreciated
Rix

Re: Using DS variables in c#

Posted: Tue Feb 11, 2025 1:22 pm
by Tony Li
Hi,

I recommend taking a slightly different approach. Maintain your variables in C#, and use C# methods / Lua functions to modify them during conversations. Please see: How To: Connect C# Variables to Dialogue System's Lua

This approach also avoids an Update() method, since it's very inefficient to call DialogueLua.GetVariable() every frame.