Page 1 of 1

Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 8:41 am
by betterlife
I need to trigger conditions for dialogues based on a number flag associated with a particular variable, for instance ("ItemInInventory_ThatOneItem", 20). I need to check for string equality, I need to be able to make numerical comparisons, and I need to be able to initialize the process from a single method, such as GetDialogue below.

If It needs to chain out to a different method that's fine, but I need to support triggering the 'option' parameter from a single call from the dialogue event system or it's going to spaghettify.

If Possible, please explain in context of what I need to do differently from what is shown in the following tutorial:

my current c#:

Code: Select all

public List<(string, double)>  GetDialogue(double option) { 
        Dictionary<string, double> storyFlagsIn = new();
        if (availableDialogueOptions.Count > option) {

            storyFlagsIn = availableDialogueOptions[(int)option].soruce?.storyVariables;
        }
        else {
            storyFlagsIn = new Dictionary<string, double>();
        }
        List<(string, double)> flags = storyFlagsIn?.Select(item => (item.Key, item.Value)).ToList() ?? new();
        flags.Add((availableDialogueOptions[(int)option].flag, 1));
        return flags;
    }
    public bool unregisterOnDisable = false;
    void OnEnable() {
        // Make the functions available to Lua
        Lua.RegisterFunction("GetDialogue", this, SymbolExtensions.GetMethodInfo(() => GetDialogue((double) 0)));
    }
    void OnDisable() {
        if (unregisterOnDisable) {
            // Remove the functions from Lua
            Lua.UnregisterFunction("GetDialogue");
        }
    }

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 9:56 am
by Tony Li
Hi,

I don't quite follow. Can you show what an example Conditions field and/or conversation excerpt would ideally look like? It can be a mock-up. It doesn't have to be working yet.

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 12:40 pm
by betterlife
Sorry, I have moved on from this approach already. I am now handling all the conditions myself, as I already have a custom version of your quest system called story system. I will be adding my own raycast buttons to each npc in the world space, I want them to trigger a specific conversation. I was thinking about enabling a DialogueSystemTrigger element with the trigger setting OnEnable that selects my conversation for me and handles some exit conditions like walking away.

The big problem I see that I still need to fix is that I need the ability to log variables with text that is unique not just to each named item in my story templates (ie, the name of a place that meets the requirements for a part of the story), but to all active copies of that story template. This would seem to require that I add the uid from each instance of the story template to the name of the lua variable I make with SetVaraible(), Which would be fine except in the corresponding conversation I would be able to write [var=StoryID_ElementID] but not the uid set at runtime. So, the named object, place, or person assigned to that version of the story would be un-referenceable.

can you think of an approach that would allow me to use variables who's name I will not know until runtime? I guess I could duplicate all my conversations say 3 times, and in each version reference StoryTemplate_VerA_ElementID or _VerB or _VerC, and then programmatically limit the number of active quests using the same template to 3, AND check to see which Letters are available, but that would be limiting and complicated.

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 2:33 pm
by Tony Li
betterlife wrote: Sat Jul 09, 2022 12:40 pmcan you think of an approach that would allow me to use variables who's name I will not know until runtime? I guess I could duplicate all my conversations say 3 times, and in each version reference StoryTemplate_VerA_ElementID or _VerB or _VerC, and then programmatically limit the number of active quests using the same template to 3, AND check to see which Letters are available, but that would be limiting and complicated.
There's no need to do that. It would be very messy. There are several ways to reference variables whose names you don't know until runtime. Can you provide a concrete example? You mention StoryID and ElementID and uid, but it's not clear what these mean.

If you don't want to provide a concrete example, here are some general tips:

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 5:51 pm
by betterlife
I don't see how I could change the variables used in the conversation panel using setvariable(), I am already using that to populate the variables at runtime. in essence I am trying to do :
varName = DemoStory.UID.ToString()(set at runtime) + "_Location_A"(from story template, I can type this in manually)
and then [var=varName] (the text I want to display)
again, this is in the conversation panel.

I am trying to wrap my head around FormattedText.ParseCode(string), perhaps this is the answer. can I run this in the text conversation? is it something like:
[var = FormattedText.ParseCode([var=demoStoryUID])_Location_A] ?
or maybe I can just do:
[var=[var=demoStoryUID]_Location_A] ?

that way I can just change the value of demoStoryUID before loading the conversation.

I don't even know how to target a conversation and prepend all the variable names, and although it is just text processing, that is a lot of searching and replacing to be doing before each conversation. Although, OnConversationLine() does seem the appropriate time to do this if I where to.

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 6:23 pm
by Tony Li
You can nest [var=variable]. This is legal:

[var=[var=demoStoryUID]_Location_A]

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 6:38 pm
by betterlife
Thank you! I'm not too far from the point where I can test it, Thank you for your help. sorry for my crazy specific problems and confusion, I'm kinda trying to slice into the middle of your system and jam my own code into the dialogue portion. Also this is my first time using lua. Thanks again!

Re: Lua conditions that specify type and amount

Posted: Sat Jul 09, 2022 7:53 pm
by Tony Li
Glad to help!