Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Mr.T on Wed 23/04/2008 22:28:45

Title: GUI Instance name for translation
Post by: Mr.T on Wed 23/04/2008 22:28:45
Greetings, I have searched about this and couldn't found an answer, to be honest I don't really
know how to name my request.

Is it possible when a game has multiple translations to do let say:

-when the game start it checks the language

-assign the gui with the language selected to an instance name

-using the instance name in the game just like it was a directly selected gui.

By doing this I'm trying to find a way to avoid re-writing for each language the

if (Game.TranslationFilename == "English") {
   GUIEnglish.Visible = true
} else if (Game.TranslationFilename == "French") {
   GUIFrench.Visible = true
} etc...


by


(globalscript)
#define GUI instance
if (Game.TranslationFilename == "English") { GUI = GUIEnglish }
} else if (Game.TranslationFilename == "French") { GUI =  GUIFrench }
etc...

(room)
GUI.Visible = true


I hope I was clear enough and it wasn't mentioned before, thank you very much for your help ;)
Title: Re: GUI Instance name for translation
Post by: monkey0506 on Wed 23/04/2008 23:39:24
What you want here is a GUI* also known as a GUI-pointer or pointer-to-GUI:

// top of script
GUI* gMultilingualMenu;

// inside the game_start function
if (Game.TranslationFilename == "English") gMultilingualMenu = gEnglishMenu;
else if (Game.TranslationFilename == "French") gMultilingualMenu = gFrenchMenu;
else if (Game.TranslationFilename == "German") gMultilingualMenu = gGermanMenu;
// etc.

// room script
gMultilingualMenu.Visible = true;


By using a GUI* we don't have to know which GUI we want to use in order to use it! In this instance you shouldn't encounter any null pointer errors, but if you're unfamiliar with pointers, you should know about them.

Basically when you create the pointer (the "GUI* gMultilingualMenu;" definition at the top of the screen), it isn't pointing to anything yet, so it holds the special value null. You can't do anything with a null pointer, doing so will crash your game. To avoid this you can make sure the pointer is non-null with a simple check such as:

if (myPointer != null) { /* do stuff! */ }
else { /* the pointer was null! we can't use it, but we may want to do some exception handling here */ }
Title: Re: GUI Instance name for translation
Post by: Mr.T on Thu 24/04/2008 08:37:05
Thank you very much Monkey_05_06 I'll try GUI* pointer  ;)
Title: Re: GUI Instance name for translation
Post by: Mr.T on Thu 24/04/2008 12:46:25
Would it be recommended to check if the instance returns NULL
in the global repeat executed function?

I could assign a default GUI in case it returns NULL but I'm affraid
it could slowdowns too much the game or something like that.

Thank you  ;)
Title: Re: GUI Instance name for translation
Post by: Mr.T on Thu 24/04/2008 17:52:09
Thank you it works just great, one note thought, it seems Game.TranslationFilename
works only with the compiled game, not the preview game inside AGS.

I'm using AGS 3.0.1 is it normal?

edit: nevermind I need to copy the TRA in the root folder  ;)
Title: Re: GUI Instance name for translation
Post by: monkey0506 on Sat 26/04/2008 03:42:30
In this example the GUI* should never be null, it should always be set in game_start. In fact, just to be sure, when you're making the list of all the languages, you could set up a final else-clause to set the default language:

if (Game.TranslationFilename == "French") gMultilingualMenu = gFrenchMenu;
else if...
else gMultilingualMenu = gEnglishMenu;
Title: Re: GUI Instance name for translation
Post by: Mr.T on Sat 26/04/2008 09:37:25
Thanks Monkey_05_06, I did as you said the check in the game start,
and I also check in repeat execute loop (we never know  ;D ) if the
pointer == null then there is the default language (English) set.

It works just fine! ;)