Forum rules - please read before posting.

Change language through Action List

Hello,
I'm working on the small game made by kids during a workshop and, because the result is good, I'd like to add an english translation.
I've followed the tutorial and everything works perfectly: the language can now be changed in the option menu of the game.
But the game is intended for people who don't usually play and don't have the habit to explore the menu option to set language.

My question is: is there a way to change the language by clicking on a hotspot?
Per example, I'd like 2 big flags (French & English) to appear when you start the game and you only have to click on one to set the language.

I hope it's not too much trouble answering my question.
Thank you for the help and sorry for the bother!

Comments

  • I haven't done yet what you need. So I can't be certain.
    If you can change the language in the menu option then there should be a way to use the same way in your first title screen. Need to look closer into it.
    Good luck, hope some other people can help.

  • As stated in the manual's section 12.7, you can set the language through script by using the function:

    AC.Options.SetLanguage (number);

    Where "number" is the language ID you wish to set it to (0 = original language, 1 = first translation, etc).

    You can place this code inside the "Run" function of a custom Action, which you can then place inside ActionLists and set the language number each time through the Action's UI.  You can read more about custom actions in this tutorial, and in section 12.3 of the manual.
  • Wonderful. And it looks so easy!
    Many thanks for your answers!!!
  • edited June 2015
    For the record, here his the custom action I wrote using Chris help & the tutorial:

    using UnityEngine;
    using System.Collections;

    #if UNITY_EDITOR
    using UnityEditor;

    namespace AC
    {
    [System.Serializable]
    public class ActionLanguage : Action
    {
    // Declare variables here
    public int newLangState;
    public ActionLanguage ()
    {
    this.isDisplayed = true;
    category = ActionCategory.Dialogue;
    title = "Set Language";
    description = "0=fr, 1=jp, 2=en";
    }
    override public float Run ()
    {
    AC.Options.SetLanguage (newLangState);
    return 0f;
    }
    #if UNITY_EDITOR
    override public void ShowGUI ()
    {
    // Action-specific Inspector GUI code here
    newLangState = EditorGUILayout.IntField ("Set Language:", newLangState);
    AfterRunningOption ();
    }
    public override string SetLabel ()
    {
    // Return a string used to describe the specific action's job.
    return (" (" + newLangState + ")");
    }
    }
    }

    It's the very first script I write so there may be mistakes but it work fine!!!
    Now I can choose language through ActionScript just by typing the number of the language ID:
    image
    Thanks again for the help!
  • Hey how are you!
    This script for this action script would be great, but it doesnt work any more.
    It has comiled errors:
    The script '...\CustomActions\ActionChangeLanguage.cs' must derive from AC's Action class in order to be available as an Action.

    Someone know thats wrong on the code?

  • edited July 2023

    The following code works for me in version 1.77.4

    i create a c# script with the following name "ActionChangeLanguage.cpp" in my CustomActions folder

    Then Paste the following code inside (delete the previous content of the file):

    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionChangeLanguage : Action
        {
    
            // Declare properties here
            public override ActionCategory Category { get { return ActionCategory.Custom; } }
            public override string Title { get { return "Change Language"; } }
            public override string Description { get { return "New Language:"; } }
    
    
            // Declare variables here
            public int newLangState;
    
            public ActionChangeLanguage()
            {
                this.isDisplayed = true;
                category = ActionCategory.Dialogue;
                title = "Set new Language";
                description = "0=es, 1=en, 2=pt";
            }
    
            public override float Run()
            {
                AC.Options.SetLanguage(newLangState);
                return 0f;
                /* 
                 * This function is called when the action is performed.
                 * 
                 * The float to return is the time that the game
                 * should wait before moving on to the next action.
                 * Return 0f to make the action instantenous.
                 * 
                 * For actions that take longer than one frame,
                 * you can return "defaultPauseTime" to make the game
                 * re-run this function a short time later. You can
                 * use the isRunning boolean to check if the action is
                 * being run for the first time, eg: 
                 */
    
    
            }
    
    
            public override void Skip()
            {
                /*
                 * This function is called when the Action is skipped, as a
                 * result of the player invoking the "EndCutscene" input.
                 * 
                 * It should perform the instructions of the Action instantly -
                 * regardless of whether or not the Action itself has been run
                 * normally yet.  If this method is left blank, then skipping
                 * the Action will have no effect.  If this method is removed,
                 * or if the Run() method call is left below, then skipping the
                 * Action will cause it to run itself as normal.
                 */
    
                Run();
            }
    
    
    #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                // Action-specific Inspector GUI code here
                newLangState = EditorGUILayout.IntField("Set Language:", newLangState);
                AfterRunningOption();
            }
    
    
            public override string SetLabel()
            {
                // Return a string used to describe the specific action's job.
                return (" (" + newLangState + ")");
            }
    
    #endif
    
        }
    
    }
    
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.