Use c# registered functions in quest descriptions

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
kimosabe
Posts: 22
Joined: Tue Aug 09, 2022 7:19 pm

Use c# registered functions in quest descriptions

Post by kimosabe »

Hi,

I used the following to be able to use a C# function in the conditions and scripts part of the dialogue system

Code: Select all

    void OnEnable()
    {
        Lua.RegisterFunction("ItemInInventory", this, SymbolExtensions.GetMethodInfo(() => ItemInInventory(string.Empty)));

    }

    void OnDisable()
    {
        Lua.UnregisterFunction("ItemInInventory");
    }

    public double ItemInInventory(string itemName)
    {
        return (double)inventoryController.GetAmountOfItem(itemName);
    }
Which works perfectly fine, now I was wondering if and how I can use that function to display the value in my quest descriptions?

Like:
Items collected:
Cheese (ItemInInventory("Cheese") / 1)

I could've sworn that I read somewhere that this is possible but I can't find it anymore or get it to work.
Any help would be appreciated!

- Kimosabe
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Use c# registered functions in quest descriptions

Post by Tony Li »

Hi,

Use the [lua(code)] markup tag.

Code: Select all

Items collected:
Cheese ([lua(ItemInInventory("Cheese"))] / 1)
kimosabe
Posts: 22
Joined: Tue Aug 09, 2022 7:19 pm

Re: Use c# registered functions in quest descriptions

Post by kimosabe »

See below
Last edited by kimosabe on Wed Aug 10, 2022 6:56 am, edited 1 time in total.
kimosabe
Posts: 22
Joined: Tue Aug 09, 2022 7:19 pm

Re: Use c# registered functions in quest descriptions

Post by kimosabe »

Tony Li wrote: Tue Aug 09, 2022 9:50 pm Hi,

Use the [lua(code)] markup tag.

Code: Select all

Items collected:
Cheese ([lua(ItemInInventory("Cheese"))] / 1)
This doesn't seem to be working for me?

Image
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Use c# registered functions in quest descriptions

Post by Tony Li »

Please use a lowercase "l" (L) in [lua(code)]
kimosabe
Posts: 22
Joined: Tue Aug 09, 2022 7:19 pm

Re: Use c# registered functions in quest descriptions

Post by kimosabe »

Tony Li wrote: Wed Aug 10, 2022 8:26 am Please use a lowercase "l" (L) in [lua(code)]
I'm an idiot, thank you very much!
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Use c# registered functions in quest descriptions

Post by Tony Li »

No worries; happy to help!
kimosabe
Posts: 22
Joined: Tue Aug 09, 2022 7:19 pm

Re: Use c# registered functions in quest descriptions

Post by kimosabe »

Tony Li wrote: Wed Aug 10, 2022 10:11 am No worries; happy to help!
Can you make sure that the method is being called right before displaying the information? Or is there a way to force update?
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Use c# registered functions in quest descriptions

Post by Tony Li »

Yes, it's called right before displaying the text. To manually update, call DialogueManager.SendUpdateTracker(). This will update the quest tracker HUD and the quest log window if the quest log window is open.
Post Reply