Simple gifting based on items?

Announcements, support questions, and discussion for the Dialogue System.
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Simple gifting based on items?

Post by CheeseY »

Hi there other Tony,


So.. i have a question, i hope this is not too complicated / crazy.

I'd like to have the player be able to choose from items he has to gift and have that displayed in the dialog options?
I have an Inventory script with a list which contains a List of 'Item'
(a class... Derived from scriptable object.)



Until now was my method was:
- I have a bool 'HasDrink' (in the dialogue system / variable tab).
- This worked as a condition that opens up a dialog path, allowing gift options.. once you gift something, the conversation ends...


But i would like to make it so the player can choose which of his items he can give away...

I have a few basic question i guess:
- Am i doing this 'wrong' is there an easier way to do this... ? I'm not a physicist, nor do i want to learn anymore programming if i can help it lol.. But... sure would like an easier way to organise this lol...

- Is the stuff below valid? I think im registering these string functions... But last i tested, they were not showing up anywhere in the dialog GUI.. and when i put them in the condition box... the conversation never went down that route...
and it's somewhat hard to test? because its buried deep in a conversation...

-- which brings me to question 3.. how can i more easily debug this condition / situation? any advice appreciated!


Code: Select all

    void OnEnable()
    {     
        Lua.RegisterFunction("HasDrinkA", this, SymbolExtensions.GetMethodInfo(() => HasDrink1()));
        Lua.RegisterFunction("HasDrinkB", this, SymbolExtensions.GetMethodInfo(() => HasDrink1()));
    }



    [SerializeField] string hasDrink1;

    public string HasDrink1()
    {
        if (Items.FindAll(x => x.thirstItem == true).Count == 0)
            return "";
        
        return Items.Find(x => x.thirstItem == true).name;

        
    }

cheers,
another Tony
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple gifting based on items?

Post by Tony Li »

Hi Tony,
CheeseY wrote: Fri Sep 09, 2022 12:52 pm- Am i doing this 'wrong' is there an easier way to do this... ?
There's probably not an easier way. Does your inventory system has a UI component? Or is it data only?

If it has a UI component, from a design perspective you may want to open up the inventory UI to let the player select an item. If you want to do this, let me know. Otherwise I'll skip it here since it's a longish subject.
CheeseY wrote: Fri Sep 09, 2022 12:52 pm- Is the stuff below valid? I think im registering these string functions... But last i tested, they were not showing up anywhere in the dialog GUI
To get your custom functions to show up in the "..." dropdown menus, add them to a CustomLuaFunctionInfo asset. In this video tutorial, jump to 2:12 for instructions on creating the CustomLuaFunctionInfo asset.
CheeseY wrote: Fri Sep 09, 2022 12:52 pm.. and when i put them in the condition box... the conversation never went down that route...
and it's somewhat hard to test? because its buried deep in a conversation...
One way to test your Lua functions is to add a Lua Console to your scene. While playing, press ~+L to open the Lua Console, and enter "return HasDrinkA()" to run your HasDrink() method and show the return value.

To test your conversation, create a temporary Dialogue System Trigger with a Start Conversation action in which you've specified a starting entry. You can use this to start the conversation closer to where it checks your Lua functions, so you don't have to click through the earlier part of the conversation.

Keep the Dialogue Editor window open on your conversation so you can see which links it thinks are valid (green arrows) and which are invalid (red arrows because Conditions evaluated false).

Also temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. This will log all of the under-the-hood info to the Console so you can trace through the decisions that it's making about the conversation.

Regarding your Lua functions, I'm not sure why you have two functions, HasDrinkA and HasDrinkB, that do the same thing. Wouldn't a single HasDrink function suffice?
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Re: Simple gifting based on items?

Post by CheeseY »

cheers for the reply...
some of that info that should make it a bit easier.



In regards to your question.. Yes, i only need one 'HasDrink' function...
But since none of this was working, and i was trying to remove possible causes... I have gutted this. The hasdrink function currently serves to return a hardcoded string - nothing more.

I figured i'd seperate it out and simplify to the degree where i could easily identify what was causing the issue...
and so... i took out all the arguments (like which slot we're referring to) and made it several functions based on slot, since i know there's only going to be a limited amount of 'choices' i want to give the player...


I thought, setting up the conditions this way it would be super easy to get those conditional dialogue nodes to show up.. but alas. even that didn't help.

Hopefully now i can work out why these conditionals are not working...

cheers
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Re: Simple gifting based on items?

Post by CheeseY »

...i think my problem was, lack of following instructions lol.



Instead of taking the custom template like instructed.. i just tried to whack the functions in my own class...
Which i'm guessing is part of the reason its not working :D
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple gifting based on items?

Post by Tony Li »

If it's still not working after following the template and the video tutorial, let me know so we can look into it further.
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Re: Simple gifting based on items?

Post by CheeseY »

edited out because no longer relevant :)
Last edited by CheeseY on Fri Sep 09, 2022 3:37 pm, edited 1 time in total.
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Re: Simple gifting based on items?

Post by CheeseY »

Ok.

I'm just gonna save a link to that video, so i can watch it in future...
Because just before the bit you linked to is the 'simpler solution' i think :D that i couldnt remember.


Anyway if i am still having issues i will reply agian but i think i'll be fine now cheers again!
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple gifting based on items?

Post by Tony Li »

Glad to help!
CheeseY
Posts: 15
Joined: Thu Aug 05, 2021 8:07 am

Re: Simple gifting based on items?

Post by CheeseY »

i got past stage 1... I have buttons appearing based on conditions, woohoo - thanks...


So i wrote another fairly simple function using the CustomLua template and this one takes the double and returns a string, so far so good...

So inside the dialog editor, my condition is HasDrink(1) and in the menu i try to use my string return function with:
[var=DrinkName(1)]
When i run the game it says 'nil' instead of 'fanta' or whatever.

So, i changed the code from:
[var=DrinkName(x)]

to

[lua(DrinkName(x)]


Now i really don't want hand holding... But if you could confirm this even correct, that'd be appreciated.

Or that i am doing something wrong -- either one is good. The part that initially confused me was the difference between having to use the lua tags for the menu but not in the condition box?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple gifting based on items?

Post by Tony Li »

Hi,

Use [lua(code)] in text such as Menu Text and Dialogue Text. Example:
  • Dialogue Text: "Man, I could really enjoy a [lua(DrinkName(1))] right about now."
Use the function by itself -- no [lua(code)] -- in Conditions and Scripts. Example:
  • Dialogue Text: "Hey, is that a Fanta in your cooler?"
  • Conditions: DrinkName(1) == "fanta"
Post Reply