Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Arcangel on Thu 25/10/2018 17:06:08

Title: How make a selection language in option Menu?
Post by: Arcangel on Thu 25/10/2018 17:06:08
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.

Title: Re: How make a selection language in option Menu?
Post by: Crimson Wizard on Thu 25/10/2018 17:30:29
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) Select

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) Select

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) Select

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.
Title: Re: How make a selection language in option Menu?
Post by: Khris on Thu 25/10/2018 17:34:42
In game_start:

  ListBox1.AddItem("Spanish");
  ListBox1.AddItem("English");
  ListBox1.AddItem("Italian");


Then change your function:
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.
Title: Re: How make a selection language in option Menu?
Post by: Arcangel on Thu 25/10/2018 18:36:12
Quote from: krisAwesome

TY work great. TY.