Problem with barks

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Problem with barks

Post by lupiyo »

Hello! It is me again Tony, sorry.

I tried to implement bark system, but i'm getting an error. At first it worked great! The tutorial is good. But I did something that broke.
I can assure you that the function is registered. I changed the debug level to information and it appears there.

I'm getting some errors message, but I can't figure out what should be. Can you help me, please?

Code: Select all

Dialogue System: Lua code 'return GetEnemyRace()  == "Wolf"' 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)
Above are the error I get.
Below are the codes that I made.

Code: Select all

 #region Lua

    public string GetEnemyRace()
    {
        Debug.Log("enemy.enemyRace.ToString() " + enemy.enemyRace.ToString());
        return enemy.enemyRace.ToString();
    }

    void OnEnable()
    {
        Lua.RegisterFunction(nameof(GetEnemyRace), this, SymbolExtensions.GetMethodInfo(() => GetEnemyRace()));
    }

    void OnDisable()
    {
        Lua.UnregisterFunction(nameof(GetEnemyRace));
    }

    #endregion
In attach is what I did on inspector..
Thanks!!
Attachments
Barks.JPG
Barks.JPG (38.78 KiB) Viewed 209 times
User avatar
Tony Li
Posts: 22133
Joined: Thu Jul 18, 2013 1:27 pm

Re: Problem with barks

Post by Tony Li »

Hi,

What GameObject is the script on? If it's on the Dialogue Manager or its children, rename the OnEnable() method to Awake(), and remove the OnDisable() method.

Otherwise, check the Console log carefully for any messages that say:

Dialogue System: Unregistering function GetEnemyRace

Maybe the function is being unregistered after you register it.
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Re: Problem with barks

Post by lupiyo »

Thank you Tony!

I have commented the onDisable and now it is finem in parts haha

I have another problem now, i wrote the register on enable in the enemy class, and for some reason, it gives me the same value when Lua execute it.

Code: Select all

 #region Lua

    public string GetEnemyRace()
    {
        Debug.Log("Start: " + enemy.enemyRace.ToString() + " " + enemy.enemyName);
        return enemyRace;
    }


    void OnEnable()
    {
        Lua.RegisterFunction(nameof(GetEnemyRace), this, SymbolExtensions.GetMethodInfo(() => GetEnemyRace()));
    }


    #endregion
The enemy race is always the same, while when I execute it outside lua, it returns the real race of the monster. I'm guessing that lua register with the first value right, so it couldn't be inside enemy class, once my game has a lot of differente enemies.

My enemy info are from a scriptable object, but in the end this doesn't matter i guess, the information is correct on the debug.log inside the function, but wrong when it is called by Lua..
  • If this is true, do you sugest to have a singleton/manager to register all my classes in Lua?
  • Is there a way to fix this inside enemy class?
Many thanks!
User avatar
Tony Li
Posts: 22133
Joined: Thu Jul 18, 2013 1:27 pm

Re: Problem with barks

Post by Tony Li »

Lua functions are registered globally. This means you can only register one function named GetEnemyRace().

Here are some ideas:

In your function, you can pass the name of the enemy, and it can return the race.

Or, if you know the enemy is the conversation's conversant, you can refer to the property DialogueManager.currentConversant, which is a reference to the conversant GameObject.
Post Reply