SOLVED:GUI font wont change with scripting?

Started by Stranga, Sun 23/04/2017 16:00:27

Previous topic - Next topic

Stranga

Hello everyone, my game has several translations, and I have custom made a font to suit some languages. However, The dialog and display font changes perfectly, but any GUI font's do not change from the default font.

Here is my code to change the games font when changing languages:

Code: ags
        case 8: if (Game.ChangeTranslation("Russian"))
      {
         // game as changed translation
         Game.NormalFont = eFontfntRussian;
         Game.SpeechFont = eFontfntRussian;
         bTranslation.Text = "Russian";
       }
    break;


I've set the translation in a switch statement for a more organized look. But as above the GUI font does not change to this. Any thoughts?

Crimson Wizard

GUI font is an individual property of each GUI object. You need to pass every button and label and change fonts for them.

I once wrote a script for doing that:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=53950.msg636543956#msg636543956

Stranga

Thanks CW, that script is a great idea! I just have a question though. Is there a way I can use that loop in the function that already switches the translation fonts? or would I have to use the
Code: ags
function ReplaceFontOnAllGUIs(int old_font, int new_font)

Crimson Wizard

#3
Quote from: Stranga on Sun 23/04/2017 16:28:21
Thanks CW, that script is a great idea! I just have a question though. Is there a way I can use that loop in the function that already switches the translation fonts? or would I have to use the
Code: ags
function ReplaceFontOnAllGUIs(int old_font, int new_font)


EDIT: Ok, I am not sure I understand what you mean.

If you want to have that loop inside your existing function, you just need to copy it there. Maybe you will have to fix variable names after that.

If I am to give an advice, I'd recommend to keep that code in its distinct function, because that would be cleaner. You just place that function before yours language-changing function, and call it inside your function:

Code: ags

Game.NormalFont = eFontfntRussian;
Game.SpeechFont = eFontfntRussian;
ReplaceFontOnAllGUIs(eFontfntEnglish, eFontfntRussian); // use actual font names here

Stranga

Thanks for the edit also CW. I've tried the code, when when I compile or test I get this error
Code: ags
GlobalScript.asc(497): Error (line 497): Undefined token 'ReplaceFontOnGUI' 

Crimson Wizard

Quote from: Stranga on Sun 23/04/2017 16:51:43
Thanks for the edit also CW. I've tried the code, when when I compile or test I get this error
Code: ags
GlobalScript.asc(497): Error (line 497): Undefined token 'ReplaceFontOnGUI' 


Have you placed ReplaceFontOnGUI function BEFORE you use it?

Stranga

I have yes, the error seems to be coming from here:


Code: ags
function ReplaceFontOnAllGUIs(int old_font, int new_font)
{
  int i = 0;
  while (i < Game.GUICount)
  {
    ReplaceFontOnGUI(gui[i], old_font, new_font);
    i++;
  }
}

Crimson Wizard

Did you put ReplaceFontOnGUI function BEFORE ReplaceFontOnAllGUIs?

Stranga

#8
I think so.
Edit My bad I missed a line in the code

Stranga

Excellent! Works Perfectly! Thanks yet again CW!

SMF spam blocked by CleanTalk