Forum rules - please read before posting.

A way to catch if dialog has only one option

Is there a way to catch player starting a dialog with only one dialog option? As there may only be the "Bye". I was hoping there would be a way to catch the initialization before the actual dialog, so I shouldn't put it in all of the dialog ALs.

Comments

  • You can hook a custom script into the OnStartConversation custom event and read the Conversation's GetNumEnabledOptions function:

    private void OnEnable () { EventManager.OnStartConversation += OnStartConversation; }
    private void OnDisable () { EventManager.OnStartConversation += OnStartConversation; }
    
    private void OnStartConversation (Conversation conversation)
    {
        if (conversation.GetNumEnabledOptions () == 1)
        {
            // Only one option available
        }
    }
    

    If you want to automatically run the only-available option, check Auto-play lone option? in the Conversation's Inspector.

  • I was hoping to create an Action out of this, but couldn't with ActionChecks. What would you recommend?

  • edited May 2022

    To check a Conversations options in an Action:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckConversationOptions : ActionCheck
        {
    
            public override ActionCategory Category { get { return ActionCategory.Dialogue; }}
            public override string Title { get { return "Check options"; }}
            public override string Description { get { return "Checks how many options are enabled on a Conversation"; }}
    
    
            public Conversation conversation;
            public int numOptions = 1;
    
    
            public override bool CheckCondition ()
            {
                return conversation.GetNumEnabledOptions () == numOptions;
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                conversation = (Conversation) EditorGUILayout.ObjectField ("Conversation:", conversation, typeof (Conversation), true);
                numOptions = EditorGUILayout.IntField ("No. of options:", numOptions);
            }
    
            #endif
    
        }
    
    }
    
  • BTW. I was wondering if there would have been a way to have this Not going to talk DialogueOption if there's only one option there could have worked here somehow.
    In any case I wouldn't like to have this option to be visible or selectable.

  • An option can be disabled to prevent it from showing, but I'm not following your intent.

    What is the specific problem you're trying to solve?

  • Hi, how could I parametrize this script?

  • A tutorial on impementing parameters in custom Actions can be found here.

    The syntax will be made easier in v1.80, but for now this will do:

    using System.Collections.Generic;
    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckConversationOptions : ActionCheck
        {
    
            public override ActionCategory Category { get { return ActionCategory.Dialogue; }}
            public override string Title { get { return "Check options"; }}
            public override string Description { get { return "Checks how many options are enabled on a Conversation"; }}
    
    
            public Conversation conversation;
            public int conversationConstantID;
            public int conversationParameterID = -1;
            private Conversation runtimeConversation;
    
            public int numOptions = 1;
            public int numOptionsParameterID = -1;
    
    
            public override void AssignValues (List<ActionParameter> parameters)
            {
                runtimeConversation = AssignFile <Conversation> (parameters, conversationParameterID, conversationConstantID, conversation);
                numOptions = AssignInteger (parameters, numOptionsParameterID, numOptions);
            }
    
    
            public override bool CheckCondition ()
            {
                return runtimeConversation.GetNumEnabledOptions () == numOptions;
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI (List<ActionParameter> parameters)
            {
                conversationParameterID = Action.ChooseParameterGUI ("Conversation:", parameters, conversationParameterID, ParameterType.GameObject);
                if (conversationParameterID >= 0)
                {
                    conversationConstantID = 0;
                    conversation = null;
                }
                else
                {
                    conversation = (Conversation) EditorGUILayout.ObjectField ("Conversation:", conversation, typeof (Conversation), true);
    
                    conversationConstantID = FieldToID <Conversation> (conversation, conversationConstantID);
                    conversation = IDToField <Conversation> (conversation, conversationConstantID, false);
                }
    
                numOptionsParameterID = Action.ChooseParameterGUI ("No. of options:", parameters, numOptionsParameterID, ParameterType.Integer);
                if (numOptions < 0)
                {
                    numOptions = EditorGUILayout.IntField ("No. of options:", numOptions);
                }
            }
    
            #endif
    
        }
    
    }
    
  • How long will it take for AC to update to 1.80?
    And how much easier will it be?

  • v1.80 will be out soon.

    The old API will still work, but with it the ShowGUI function could be reduced to the following:

    public override void ShowGUI (List<ActionParameter> parameters)
    {
        ComponentField ("Converation:", ref conversation, ref conversationConstantID, parameters, ref conversationParameterID);
        IntField ("No. of options:", ref numOptions, parameters, ref numOptionsParameterID);
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.