Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stranga on Sun 23/04/2017 16:00:27

Title: SOLVED:GUI font wont change with scripting?
Post by: Stranga on Sun 23/04/2017 16:00:27
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) Select
        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?
Title: Re: GUI font wont change with scripting?
Post by: Crimson Wizard on Sun 23/04/2017 16:09:10
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
Title: Re: GUI font wont change with scripting?
Post by: 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) Select
function ReplaceFontOnAllGUIs(int old_font, int new_font)
Title: Re: GUI font wont change with scripting?
Post by: Crimson Wizard on Sun 23/04/2017 16:29:54
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) Select
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) Select

Game.NormalFont = eFontfntRussian;
Game.SpeechFont = eFontfntRussian;
ReplaceFontOnAllGUIs(eFontfntEnglish, eFontfntRussian); // use actual font names here
Title: Re: GUI font wont change with scripting?
Post by: 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) Select
GlobalScript.asc(497): Error (line 497): Undefined token 'ReplaceFontOnGUI'
Title: Re: GUI font wont change with scripting?
Post by: Crimson Wizard on Sun 23/04/2017 16:52:35
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) Select
GlobalScript.asc(497): Error (line 497): Undefined token 'ReplaceFontOnGUI'


Have you placed ReplaceFontOnGUI function BEFORE you use it?
Title: Re: GUI font wont change with scripting?
Post by: Stranga on Sun 23/04/2017 17:01:26
I have yes, the error seems to be coming from here:


Code (ags) Select
function ReplaceFontOnAllGUIs(int old_font, int new_font)
{
  int i = 0;
  while (i < Game.GUICount)
  {
    ReplaceFontOnGUI(gui[i], old_font, new_font);
    i++;
  }
}
Title: Re: GUI font wont change with scripting?
Post by: Crimson Wizard on Sun 23/04/2017 17:09:06
Did you put ReplaceFontOnGUI function BEFORE ReplaceFontOnAllGUIs?
Title: Re: GUI font wont change with scripting?
Post by: Stranga on Sun 23/04/2017 17:17:29
I think so.
Edit My bad I missed a line in the code
Title: Re: GUI font wont change with scripting?
Post by: Stranga on Sun 23/04/2017 17:23:56
Excellent! Works Perfectly! Thanks yet again CW!