Forum rules - please read before posting.

Display translated text of an inventory item from script?

edited August 2021 in Technical Q&A

Hi everyone,

I made a script where I get the alt label of an inventory item and pass it into a text object, like so:

InvItem myItem = KickStarter.runtimeInventory.GetItem(0);
Text myText.text = myItem.altLabel;

This works well for the original text, but if I change my game's language to something else it still displays the original text and not the translated text. I know I can create a new menu element that will do this but I have a hundred inventory items and rather not have to create a hundred menu elements for my items. Does anyone know if there's a way to display the translated version of an item's label through script?

I'm on Unity 2018.4.30 and AC 1.70.4.

Thanks

Comments

  • edited August 2021

    You can use the InvItem class's GetLabel function, passing in the intended language index as a parameter, to get the correct text.

    The current language index can be gotten with:

    Options.GetLanguage ();
    

    Try this:

    InvItem myItem = KickStarter.runtimeInventory.GetItem(0);
    Text myText.text = myItem.GetLabel (Options.GetLanguage ());
    
  • That worked! Thanks, Chris!

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.