How make a selection language in option Menu?

Started by Arcangel, Thu 25/10/2018 17:06:08

Previous topic - Next topic

Arcangel

I see that in Kathy Rain Options.

Select 5 languages:Mine only have 3 :tongue:

I think is with:
function ListBox1_OnSelectionChanged(GUIControl *control)
{
if (Game.ChangeTranslation("Spanish") == true)
{
  (Game.ChangeTranslation("Spanish");
}

}

But how I fill the selection in the option panel.


Crimson Wizard

#1
There is no way to know what languages are available using built-in commands, which is a design oversight of AGS, but you should be able to work around that by getting a list of "*.tra" files in the game directory:

Code: ags

ListOfTranslations.FillDirList("$INSTALLDIR$/*.tra");


where ListOfTranslations is a ListBox (which may also be hidden, if you dont want to show it directly).
You may still need to edit the resulting list by taking each item and stripping the ".tra" part. Something like -
Code: ags

for (int i = 0; i < ListOfTranslations.ItemCount; i++)
{
    String item = ListOfTranslations.Items[i];
    String newItem = item.Substring(0, item.Length - 4);
    ListOfTranslations.Items[i] = newItem;
}


To change the language:
Code: ags

function ListOfTranslations_OnSelectionChanged(GUIControl *control)
{
    String newLang = ListOfTranslations.Items[ListOfTranslations.SelectedIndex];
    Game.ChangeTranslation(newLang);
}


I haven't tested this, so might need some fixes or improvement here and there.

Khris

In game_start:

Code: ags
  ListBox1.AddItem("Spanish");
  ListBox1.AddItem("English");
  ListBox1.AddItem("Italian");


Then change your function:
Code: ags
function ListBox1_OnSelectionChanged(GUIControl *control)
{
  String tra = ListBox1.Items[ListBox1.SelectedIndex];
  if (!Game.ChangeTranslation(tra)) Display("Unable to change translation to %s!", tra);
}


I'll also recommend renaming the GUI control from "ListBox1" to something like "lbTranslation", to make the code more readable.

Arcangel

Quote from: krisAwesome

TY work great. TY.

SMF spam blocked by CleanTalk