Calling Method with Lua
Posted: Mon Nov 14, 2022 12:25 pm
Hi,
I'm trying to call a Method in a conversation to Open a Shop in another script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ShopTrigger : MonoBehaviour
{
public ItemData[] itemsToSell;
public void TriggerShop()
{
ShopManager.instance.OpenShop(itemsToSell);
}
void OnEnable()
{
Lua.RegisterFunction("TriggerShop", this, SymbolExtensions.GetMethodInfo(() => TriggerShop()));
}
void OnDisable()
{
Lua.UnregisterFunction("TriggerShop");
}
As You can see, I use Item data to keep track of the items the NPC has to sell, and I wanted to trigger the shop a conversation. Using the tutorial on Youtube, that's what I came to, but in the console, as I run the game, I get this :
Dialogue System: Lua code ' ShopTrigger()' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
Can you tell me what I did wrong ?
Thank you very much,
Jean
I'm trying to call a Method in a conversation to Open a Shop in another script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ShopTrigger : MonoBehaviour
{
public ItemData[] itemsToSell;
public void TriggerShop()
{
ShopManager.instance.OpenShop(itemsToSell);
}
void OnEnable()
{
Lua.RegisterFunction("TriggerShop", this, SymbolExtensions.GetMethodInfo(() => TriggerShop()));
}
void OnDisable()
{
Lua.UnregisterFunction("TriggerShop");
}
As You can see, I use Item data to keep track of the items the NPC has to sell, and I wanted to trigger the shop a conversation. Using the tutorial on Youtube, that's what I came to, but in the console, as I run the game, I get this :
Dialogue System: Lua code ' ShopTrigger()' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
Can you tell me what I did wrong ?
Thank you very much,
Jean