Page 1 of 1

Registered function doesn't work

Posted: Sun Mar 01, 2020 2:10 pm
by jjpixelc
Hi

I have registered a C# method via RegisterFunction() and I am now trying to run it during a dialogue.
The method controls an image panel that should show different images during dialogues.
The method is on my GameManager script/object and is also registered from that script.
The method works fine when I just run it from Start() in the GameManager script, but nothing happens when I use it in dialogues. The image does not get added to the panel.
I have a feeling I am missing something simple here.
Maybe I have misunderstood what a registered function can be used for?

Here is my method in GameManager:

Code: Select all

public void SetDialogueImage(string imageName)
    {
        var newSprite = dialogueSprites.Find(x => x.name == imageName);
        dialogueImage.sprite = newSprite;
        dialogueImage.gameObject.SetActive(true);
    }
Here is my registration code in GameManager:

Code: Select all

void OnEnable()
    {
        Lua.RegisterFunction("SetDialogueImage", this, typeof(MyLuaFunctions).GetMethod("SetDialogueImage"));
        Lua.RegisterFunction("ClearDialogueImage", this, typeof(MyLuaFunctions).GetMethod("ClearDialogueImage"));
    }

void OnDisable()
    {
        Lua.UnregisterFunction("SetDialogueImage");
        Lua.UnregisterFunction("ClearDialogueImage");
    }
Here is the LUA code in the script field of the node:

Code: Select all

SetDialogueImage("Bible_Open_512")

Re: Registered function doesn't work

Posted: Sun Mar 01, 2020 3:58 pm
by Tony Li
Hi,

Are there any warnings or errors in the Console when the conversation gets to that node?

If you temporarily set the Dialogue Manager's Other Settings > Debug Level to Info, do you see lines like this?

Code: Select all

Dialogue System: Registering Lua function SetDialogueImage
Dialogue System: Registering Lua function ClearDialogueImage
You can also try adding a Lua Console component to your scene. At runtime, press ~+L to open the Lua Console, then enter the same Lua code that's in your Script field.

Re: Registered function doesn't work

Posted: Fri Mar 06, 2020 2:05 pm
by jjpixelc
Hi

The messages you described show up and I also get this message afterwards:

Dialogue System: Lua(SetDialogueImage("Bible_512"))
UnityEngine.Debug:Log(Object)

So everything looks fine.
(the parameter is different form my above example, but that is on purpose)

I would love to test it in the Lua console, but I cannot open it as I am on a small Danish keyboard and the tilde key is not available to me.
Can you provide another way of opening the Lua console?

Re: Registered function doesn't work

Posted: Fri Mar 06, 2020 2:12 pm
by jjpixelc
Just to add:

When I use SendMessage() in the sequencer field instead, everything works fine:

SendMessage(SetDialogueImage, Bible_512, GameManager)

Re: Registered function doesn't work

Posted: Fri Mar 06, 2020 2:19 pm
by Tony Li
If you inspect the Lua Console component, you can assign a different key combination that doesn't use tilde.

You can also try temporarily adding a Debug.Log line to SetDialogueImage to log when it's called and/or set a breakpoint in the method. Maybe for some reason it's not able to find the sprite by name or something like that.

Re: Registered function doesn't work

Posted: Sat Mar 07, 2020 4:13 am
by jjpixelc
Thanks for quick reply - will try these things out!

Re: Registered function doesn't work

Posted: Sun Mar 08, 2020 8:36 am
by jjpixelc
Hi again

Just wanted to say that I got it to work.
Just some simple errors on my part - but your guidance relating to the console helped me sort them out.
Thanks for prompt replies!

Re: Registered function doesn't work

Posted: Sun Mar 08, 2020 9:06 am
by Tony Li
Happy to help! :-)