Forum rules - please read before posting.

Check language from variable

edited December 2014 in Technical Q&A
There is an easy way to assign to a global or local integer variable which language I'm using?
I have some 3d text (text mesh) that I would like to change when player change the language. So, setting the "on variable change" cutscene, I can change them all.
Or some other way to change them "on the fly" when player switch between language cycles.
Tx.

Comments

  • The language number can be determined with:

    Options.GetLanguage ();

    So to assign this to e.g. a Local integer Variable of ID=2:

    LocalVariables.SetIntegerValue (2, Options.GetLanguage ());
  • Ok, but, I'm ignorance in Unity, so where I have to put this line of code?
    I tried to create a new script but it tells me that LocalVariables does not exist in the current context.

    :(|)
  • Sorry, that should be AC.LocalVariables


  • Ok, works great, tx!

    For help someone other, I create a new C script called CheckLanguage and put this line under the Void Update.

    Then I attached the script to the Main Camera so everytime I change the language from the Menu it change on the fly!

    Maybe it's not a perfect and correct solution but it works! 

    using UnityEngine;
    using System.Collections;

    public class CheckLanguage : MonoBehaviour {

    // Use this for initialization
    void Start () {
    }
    // Update is called once per frame
    void Update () {
    AC.LocalVariables.SetIntegerValue (41, AC.Options.GetLanguage ());
    }
    }
  • Hi, I have to change a scene object based on language. I have created this script and put it in the main camera, but I don't know what I have to do now to be able to detect the language within an action list.

    Can someone explain it to me please? I think that this is a very usefull thing. :smiley:

  • See the Manual's "Save scripting" chapter. The active language can be read with:

    AC.Options.GetLanguage ();
    

    Alternatively, you can use the Custom: Check Language Action.

  • edited September 2020

    Thanks! The Custom: Check Language Works fine! :) <3

  • edited October 2020

    Sorry, I put the CheckLanguage script in the Main Camera and This error appears in the Consoles:

    **NullReferenceException: Object reference not set to an instance of an object

    AC.LocalVariables.SetIntegerValue (System.Int32 _id, System.Int32 _value) (at Assets/AdventureCreator/Scripts/Variables/LocalVariables.cs:281)**

    Can this exception affect to the Action List? I put the Check Language Action in an action list and it seems like it works, but i´m not sure because I don´t have more than a language in my project yet.

    Using AC v1.71.4

    Thanks

  • The CheckLanguage script above is separate from the ActionCheckLanguage Action script - the error in the first won't affect the second.

    The error is that it cannot find the local variable with the given ID number - which is hard-coded to 41 in 2finger's code. You'll need to change this to the ID of the local variable you want to affect.

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.