Forum rules - please read before posting.

A fake messenger system

Hi there,

I'm working on creating a fake messenger system for my game, and I'm using the ChatLog.cs script (https://adventure-creator.fandom.com/wiki/Chat_log) to help with that.

What I'm trying to do is display the text of the conversation option that the player selects in a 'fake text input field' UI, as if the player had typed it themselves. I've set this up using a Global Variable (String) and created an element in the Messenger menu to display it as a Global Variable Label Type.

Then, when the player clicks the 'Send' button, the text in the Global Variable Label gets cleared out, and the text is finally displayed in the chat log.

My concern is that as the game develops, this approach will require managing many, many Global Variables (Pop-ups), which could become cumbersome. I'm wondering if there's a more efficient way to achieve the same effect.
Any advice or suggestions would be greatly appreciated.

https://imgur.com/a/CM4CC7f

Comments

  • There's a couple of simplifications you can make.

    Firstly, you can automate the setting of the String variable by having a script that simply sets it to the label of the last-clicked Conversation option:

    using UnityEngine;
    using AC;
    
    public class AutoSetOptionString : MonoBehaviour
    {
    
        public string variableName = "a/Messenger";
    
        void OnEnable () { EventManager.OnClickConversation += OnClickConversation; }
        void OnDisable () { EventManager.OnClickConversation -= OnClickConversation; }
    
        void OnClickConversation (Conversation conversation, int optionID)
        {
            string label = conversation.GetOptionNameWithID (optionID);
            GlobalVariables.GetVariable (variableName).TextValue = label;
        }
    
    }
    

    Secondly, you can use this variable as a token within your Dialogue: Play speech Action, to avoid having to re-type it.

    This token is of the form [var:ID], so if the "a/Messenger" variable's ID is 30, you can set the speech text to [var:30] to display it.

  • Thank you so much for your help! This script makes the process much easier to manage.

  • May I ask one more question? My initial concern was about handling the other Global Pop-up Variables, and I apologize for not being clearer earlier. I realized that my previous screenshot missed one of the Global Variable Actions.

    Here’s the updated screenshot: https://imgur.com/a/yKtLgfH

    In my ActionList that contains the Conversation Action, I’ve included a Global Variable to remember the choice of the conversation option. When the player clicks the Send button, it goes through the Variable (Variable: Check) and then runs an Action that triggers the appropriate dialogues. Currently, I only have one case set up, but as I add more conversations, there will be more variables to check. I was wondering if there’s a better approach to handle this as the complexity increases?

  • If you have each response defined as a separate ActionList, you can define a GameObject parameter within a new list that stores the intended list to run.

    After the Dialogue: Start Conversation Action, you can then use ActionList: Set parameter to set this GameObject parameter as appropriate. Then, when you click "Send", run this ActionList and have it use this parameter in the ActionList: Run Action. It'll then run the response list that you assigned earlier.

  • I can't thank you enough! Your solution is incredibly useful in many different parts of my game. It's going to save me a significant amount of development time. Thank you so much again.

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.