Lift System & Dynamic Dialogue Entries

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Lift System & Dynamic Dialogue Entries

Post by Mackerel_Sky »

Hi there,

I'm working on adding a menu to a lift that the player can use to select which floor they wish to travel to. I had a quick look through the documentation and the forums and managed to generate entries depending on how many floors the lift had in its destination list.

I have a couple of questions regarding the rest of the implementation:

1. I can't seem to delete the entries after the end of the conversation- can't really seem to find any information that specifies how to remove a dialogue entry. Is there a way to do this?

My current code is like this:

Code: Select all

        public void AddMenuOptions()
    {
        var template = Template.FromDefault();
        int newLevelID = conversation.dialogueEntries.Max(existingEntry => existingEntry.id);
        DialogueEntry menuEntry = conversation.GetDialogueEntry(liftMenuID);
        for (int i = 0; i < localWaypoints.Length; i++) //for every floor stored in the lift controller
        {
            if (i != DialogueLua.GetVariable("LiftPosition").asInt) //if we are not already on this floor, add a dialogue entry
            {
                newLevelID++;
                var newEntry = template.CreateDialogueEntry(newLevelID, conversation.id, "Level " + (newLevelID-1).ToString()); //-1 because id 1 is taken by menu node
                newEntry.ActorID = 1;
                newEntry.DialogueText = "Level " + (newLevelID - 1).ToString();
                conversation.dialogueEntries.Add(newEntry);
                var link = new Link(conversation.id, liftMenuID, conversation.id, newEntry.id);
                menuEntry.outgoingLinks.Add(link);
            }
        }
    }


    public void ResetMenuOptions()
    {
        for (int i = 2; i < conversation.dialogueEntries.Count; i++) //for every node beyond the menu in the lift conversation
        {
            DialogueEntry entry = conversation.dialogueEntries[i];
            //delete the node?????????????????
        }
    }

2. I wrote a sequencer command to move the lift to the position the player selected. However, I need to get a reference to the lift controller script which I cannot specify as the listener or the speaker in the conversation due to the conversation being used across multiple instances.

I tried using ConversationStarter.conversant, but got an 'object reference is required for a non-static field, method or property' error. I manually set the conversant in the Dialogue System Trigger component of the lift, using the Start Conversation action. Is there a way around this error? I don't think I should use GameObject.Find because there could be multiple different lifts in the scene.

Thanks for your help!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lift System & Dynamic Dialogue Entries

Post by Tony Li »

Hi,

If you want to create a conversation at runtime, you'll need to create an entire dialogue database at runtime. Please see this post for instructions.

However, it may be much simpler to make a conversation in the Dialogue Editor that has the maximum number of floors. Use Conditions to show only the number of floors that the current lift has:

elevatorConversation.png
elevatorConversation.png (31.85 KiB) Viewed 687 times

Register a C# method with Lua that returns the number of floors that the current lift has. Example:

Code: Select all

double GetNumFloors()
{
    var lift = DialogueManager.currentConversant;
    if (lift == null) return 1; // Dummy value if current conversation hasn't been set yet.
    return list.GetComponent<MyLiftScript>().numFloors;
}
Or just set a Dialogue System variable when the player enters the lift and check that in the Conditions:

Code: Select all

DialogueLua.SetVariable("NumFloors", thisLift.numFloors);
Write a sequencer command like GotoFloor(#) -- or GotoFloor() with no parameter, that goes to the floor indicated by the current conversation state:

Code: Select all

public void SequencerCommandGotoFloor() // skipping some code here for brevity
{
    void Awake()
    {
        string floorName = DialogueManager.currentConversationState.subtitle.formattedText.text;
        int floorNum = SafeConvert.ToInt(floorName);
        // Go to floorNum.
    }
}
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: Lift System & Dynamic Dialogue Entries

Post by Mackerel_Sky »

Hey Tony,

Thanks for the help as usual. I ended up going with the max floors and conditions method - I made an numerical varIable for the max floors a lift can go to, set it on conversation start with the control panel, and reset it to 0 after the lift moves.

Is there a way to reference the Dialogue Entry ID in the Lua code used for the condition? While not game-breaking, I'd like to remove the floor that the lift is currently on as an option.

Thanks,
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lift System & Dynamic Dialogue Entries

Post by Tony Li »

What if you also use OnconversationStart to set another variable that indicates the current floor? Then you can set, for example, floor button 5's Conditions to:

Code: Select all

Variable["CurrentFloor"] ~= 5 and Variable["MaxFloors"] <= 5
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: Lift System & Dynamic Dialogue Entries

Post by Mackerel_Sky »

Hey Tony,

That's a great idea. Think everything is working as intended now- appreciate the help!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lift System & Dynamic Dialogue Entries

Post by Tony Li »

Glad to help! :-)
Post Reply