Forum rules - please read before posting.

Translatable Custom Actions script

Hi, like some other users, I've created some action lists with parameters to perform repetitive actions and display texts. However, the translation tool isn't gathering these texts. I saw a potential solution using the Translatable custom script. Since I'm not a programmer, I'm not sure how easy it would be to implement this. I asked ChatGPT for help, and it created a modified version where I can connect the action list to the script, but it's not working perfectly.

Could someone provide a brief explanation of how this script is supposed to work? I assume that the text should be displayed dynamically in the fields. Should this script be in each of the hotspots with a template action list containing texts?

This is my current script:

using UnityEngine;
using AC;

[HelpURL("https://www.adventurecreator.org/scripting-guide/class_a_c_1_1_custom_translatable_example.html")]
public class TranslatableLookAtParameter : MonoBehaviour, ITranslatable
{
    public ActionList lookAtActionList; // Reference to the ActionList containing the parameters
    public int parameterID; // ID of the parameter containing the text

    private string parameterText;
    private int parameterLineID = -1;

    private void OnEnable()
    {
        EventManager.OnChangeLanguage += OnChangeLanguage;
        UpdateParameterText();
    }

    private void OnDisable()
    {
        EventManager.OnChangeLanguage -= OnChangeLanguage;
    }

    private void OnChangeLanguage(int language)
    {
        // Update parameter text when language changes
        parameterText = KickStarter.runtimeLanguages.GetTranslation(parameterLineID);
    }

    private void UpdateParameterText()
    {
        // Get parameter text
        if (lookAtActionList != null && lookAtActionList.parameters != null)
        {
            ActionParameter parameter = lookAtActionList.GetParameter(parameterID);
            if (parameter != null && parameter.parameterType == ParameterType.String)
            {
                parameterText = parameter.stringValue;
            }
        }
    }

    public string GetTranslatableString(int index)
    {
        return parameterText;
    }

    public int GetTranslationID(int index)
    {
        return parameterLineID;
    }

#if UNITY_EDITOR

    public void UpdateTranslatableString(int index, string updatedText)
    {
        parameterText = updatedText;
    }

    public int GetNumTranslatables()
    {
        return 1;
    }

    public bool CanTranslate(int index)
    {
        return !string.IsNullOrEmpty(parameterText);
    }

    public bool HasExistingTranslation(int index)
    {
        return (parameterLineID >= 0);
    }

    public void SetTranslationID(int index, int lineID)
    {
        parameterLineID = lineID;
    }

    public string GetOwner(int index)
    {
        return string.Empty;
    }

    public bool OwnerIsPlayer(int index)
    {
        return false;
    }

    public AC_TextType GetTranslationType(int index)
    {
        return AC_TextType.Custom;
    }

#endif
}

Comments

  • The script looks like it ought to be picked up by the "Gather Text" process - see the provided CustomTranslatableExample script for a commented example script on implementing ITranslatable.

    The issue looks to be that the script never updates the parameter value - UpdateParameterText has it the other way around.

    Try swapping it round so that it reads:

    parameter.stringValue = parameterText;
    

    And have this function also run at the end of OnChangeLanguage.

  • I tried to capture the text but wasn't successful. I'll just use the speech action directly instead.

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.