Hi, Ive been trying to link my C# script method into lua so that i can call it from any dialogue nodes. The problem is only 1 of all method references that is working on the dialogue node lua script which is the "AddIntelligence" one. When i try to implement the rest of the method it will reply an expection like this "Dialogue System: Lua code 'AddCreativity(1)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'" i dont really know if i do something wrong cause i just followed the youtube tutorial "Dialogue System for Unity 2.x - Connecting Your C# Methods to Lua" .
Could somebody please enlighten me on what do i do wrong?
Tried to invoke a function call on a non-function value
Re: Tried to invoke a function call on a non-function value
I dont know why i constantly get spam report when i try to add my code snippets so ill just attach an image here
- Attachments
-
- rest.PNG (30.71 KiB) Viewed 808 times
Re: Tried to invoke a function call on a non-function value
Thanks for posting the code. The issue is that the OnDisable() method is unregistering all of your functions except AddIntelligence. If you look closely at the method, "AddIntelliigence" is misspelled, which means "AddIntelligence" is not being unregistered.
The solution is to make sure OnDisable() isn't called. If you're adding this script to your Dialogue Manager GameObject, you can just remove the OnDisable() method.
The solution is to make sure OnDisable() isn't called. If you're adding this script to your Dialogue Manager GameObject, you can just remove the OnDisable() method.
Re: Tried to invoke a function call on a non-function value
Thanks for the answer it works like a charm! i thought the OnDIsable part is mandatory since it is written in the TemplateCustomLua.cs. I have another question, where is the apropriate place to add the script?. I tried to put it on a Seperate GameObject and try to get an instance of another object from Serialize FIeld in the script so that it can call another a function from another object. But, when i call the function from lua, the another object that i instantiate through serialize field is not found. i had to use GameOject.Find method to resolve this. so i asume the method that i call from Lua Script in the dialogue node is not the same instance as the one in the Seperate Game object. ive been looking for the documentation but cant seem to find it. Thanks
Re: Tried to invoke a function call on a non-function value
Hi,
If you want the function to always be available in all scenes, put it on the Dialogue Manager, and don't use OnDisable(). In your C# method, use GameObject.Find() or something similar to access other GameObjects.
If you only want the function available in a specific scene, put it on a different GameObject in the scene, and include OnDisable(). In this case, your C# method should be able to access a different GameObject that's referenced by [SerializeField]. However, if you're instantiating that GameObject, make sure you update the field to point to the instantiated copy and not the original prefab.
If you want the function to always be available in all scenes, put it on the Dialogue Manager, and don't use OnDisable(). In your C# method, use GameObject.Find() or something similar to access other GameObjects.
If you only want the function available in a specific scene, put it on a different GameObject in the scene, and include OnDisable(). In this case, your C# method should be able to access a different GameObject that's referenced by [SerializeField]. However, if you're instantiating that GameObject, make sure you update the field to point to the instantiated copy and not the original prefab.