Forum rules - please read before posting.

Customize conversation at runtime

My adventure game has a part where the player has to answer a few random questions in order to proceed.

As I have imagined it, I need to create a loop: a "play speech" action where a question is stated, leading to a "start conversation" action with the possible answers (as conversation options), then going back to the "play speech" action as long as the player answers correctly. The speech and the conversation actions must refresh on each loop, picking new content each time from an external file, since there will be tens, maybe hundreds of questions.

Ideally, I'd also like to randomise the order of the conversation options, but this is not 100% necessary.

I searched in the scripting guide a bit but didn't find a straightforward way of editing action contents.

Any leads?


  • Actions can be modified through use of ActionList parameters, but the Dialogue: Start conversation Action is just a means to activate a Conversation present in the scene. If you want to modify the options available, you'll want to do so by updating the Conversation at runtime - not the Action.

    What kind of data are we looking at, exactly, to load in from an external file?

    You can modify the Conversation's labels easily enough, but more complex would be the need to update which option is the correct one. I'd imagine the best way would be to rely on an Integer variable (could be Component, could be Global), that is used to record the correct option index - and then each option checks this against itself when run.

    Going back to ActionList parameters, you can use these to update the speech Actions with the answers pulled in from the external file.

    I'll try to give steps to show what I mean - this'll be for a question with 3 answers.

    1. Create a new Global Integer named "AnswerIndex".
    2. Create a new Conversation with three options. We can still use the Override options? feature, so you don't need to define DialogOptions for them.
    3. In a new ActionList, define 4 String parameters named "Question", "AnswerA", "AnswerB", "AnswerC"
    4. Then set up your Actions like so:

    Here, the speech Actions to show the question and the answers are set to show the parameters created in step 3. Each answer then checks its own index against the Integer parameter to see if it was correct or not.

    What we now need is to set:

    • The AnswerIndex integer variable
    • The Conversation's option labels
    • The parameter values

    To set a Global integer variable's value, call:

    GlobalVariables.GetVariable ("AnswerIndex").IntegerValue = myNewValue;

    To set a Conversation's option labels, call:

    myConversation.GetOption (0).label = answerAText;
    myConversation.GetOption (1).label = answerBText;
    myConversation.GetOption (2).label = answerCText;

    And to set parameter values, call:

    myActionList.GetParameter ("Question").stringValue = questionText;
    myActionList.GetParameter ("AnswerA").stringValue = answerAText;
    myActionList.GetParameter ("AnswerB").stringValue = answerBText;
    myActionList.GetParameter ("AnswerC").stringValue = answerCText;
  • You 're the best! I'm so glad I've paid full price for this asset, I'd feel bad if I hadn't :)

    In case anyone needs to implement the same thing, here's my external code (called via Object: Send Message, just before displaying the question) :

    string data = "How much is 1+1;#2#3#11#639";
    public ActionList RiddleGame;
    public Conversation riddleAnswers;
    public void GetRandomRiddle() {
            string[] qData = data.Split('#');
            RiddleGame.GetParameter("Question").stringValue = qData[0];
            // Randomize answers order and mark the correct one (initially it's the first one)
            int numberOfAnswers = riddleAnswers.options.Count;
            int offset = Random.Range(0, numberOfAnswers);
            for (int i = 0; i < numberOfAnswers; i++)
                int targetIndex = 1 + (i + offset) % numberOfAnswers;
                riddleAnswers.GetOption(i).label = qData[targetIndex];
                if (targetIndex == 1) GlobalVariables.GetVariable("AnswerIndex").IntegerValue = i;
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.