Registered function doesn't work

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Registered function doesn't work

Post 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")
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Registered function doesn't work

Post 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.
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Re: Registered function doesn't work

Post 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?
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Re: Registered function doesn't work

Post by jjpixelc »

Just to add:

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

SendMessage(SetDialogueImage, Bible_512, GameManager)
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Registered function doesn't work

Post 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.
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Re: Registered function doesn't work

Post by jjpixelc »

Thanks for quick reply - will try these things out!
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Re: Registered function doesn't work

Post 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!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Registered function doesn't work

Post by Tony Li »

Happy to help! :-)
Post Reply