Forum rules - please read before posting.

Speech event tokens not working?

Hi folks, I'm trying to use the new OnRequestSpeechTokenReplacement event with the basic example in the manual, but each time I use it in the Dialogue action I get only a [random:animal] text rather than the replacement text.

This is the code>

using UnityEngine;
using System.Collections;
using AC;

public class SpeechEventTokenKeys : MonoBehaviour
{
    private void OnEnable()
    {
        KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "random" };
        EventManager.OnRequestSpeechTokenReplacement += OnRequestSpeechTokenReplacement;
    }
    private void OnDisable()
    {
        EventManager.OnRequestSpeechTokenReplacement -= OnRequestSpeechTokenReplacement;
    }
    private string OnRequestSpeechTokenReplacement(Speech speech, string tokenKey, string tokenValue)
    {
        if (tokenKey == "random" && tokenValue == "animal")
        {
            string[] animals = new string[5] { "Cat", "Dog", "Parrot", "Bear", "Monkey" };
            int i = Random.Range(0, animals.Length);
            return animals[i];
        }
        return string.Empty;
    }
}

This is the actionlist event>

Comments

  • edited August 2019

    The code works for me. At what point are you running the ActionList, and is the script added to a GameObject within the scene file?

    AC and Unity versions?

  • edited August 2019

    I'm using it via a Menu Action List. Unity 2018.3.14f1 and AC 1.68.4

    EDIT>

    It worked after I added the script as a component in the on start cutscene. How can I use that script or add it as a component for an UI windows that appears from a set of action lists?

  • Yes, it's a component script - nothing to do with Actions.

    The script only affects the speech text itself - it's separate from any Subtitles menu that may display it. Just having it on an empty GameObject in your scene will be enough for it to work, regardless of how you're showing the subtitles text.

  • Thanks Chris! You're a pal :D

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.