• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

help multi lenguage

T

tavo

Guest
Hi new guy here. long time forum stalker, (lol)

I recently made a game but I want english and spanish lenguage options

here is an example hw my dialogues work.....

here is the code for the dialogue boxes

obj_naza_words

///////create event.////////
text1 = string(" ERROR ERROR ,")
text2 = string(" ¡NOO! ACASO TODA LA MIS ROLAS# DEL ARES QUE BAJE A SU# DISCO DURO LO ALENTO.")
text3 = string(" ERES UN COMPLETO IDIOTA.")

talk = 1

global.text = true
out = string("")
spd = 0


//////step event//////////
////talk
if talk = 1{
out = string_copy (text1,1,spd)
spd +=0.5
}
if talk = 2{
out = string_copy (text2,1,spd)
spd +=1
}
if talk = 3{
out = string_copy (text3,1,spd)
spd +=1
}
var platica = keyboard_check_pressed(vk_space);
if gamepad_is_connected(0){
platica = gamepad_button_check_pressed(0,gp_face3);
}

if platica{
talk +=1
spd = 0
}

if talk > 3
instance_destroy();



/////draw event

draw_set_font(font_start)
draw_set_valign(fa_top)
draw_set_halign (fa_left)

if talk = 1{
draw_sprite(spr_naza,2,view_xview[0],view_yview[0]+200)
draw_set_color(c_white)
draw_text(view_xview[0], view_yview[0]+200, out)

}
if talk = 2{

draw_sprite(spr_naza,5,view_xview[0],view_yview[0]+200)
draw_set_color(c_white)
draw_text(view_xview[0], view_yview[0]+200, out)

}
if talk = 3{
draw_sprite(spr_naza,0,view_xview[0],view_yview[0]+200)
draw_set_color(c_white)
draw_text(view_xview[0], view_yview[0]+200, out)

}

/////destroy event
global.text = false

I want to have an option to change the text strings in the create event for example
text3 = string(" ERES UN COMPLETO IDIOTA.")

have an option in english to say something like this
text3 = string(" You're a complete IDIOT!!!!")



iM KINDA new using game maker, thanks in advance.
 
T

tavo

Guest
ALMOST SOLVED USING INI FILES

FIRST I created a new script

////init_lenguage

globalvar TRANS;

TRANS=ds_map_create();
ini_open("Languages.ini");

TRANS[? "Text1"]=ini_read_string(global.drawlang,"Text1","default");
ini_close();


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
then inserted an ini file in the included files section
[en]
Text1 =this one is the first text

[es]
Text1 = este es el texto uno


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
then created the text box object

create event
////prueba de texto
text1 = string(1)

talk = 1

global.text = true
out = string("")
spd = 0


////step event
out = string_copy ((TRANS[? "Text1"]),1,spd)
spd +=0.5
}


if talk > 1
instance_destroy();



/////draw event

draw_set_font(font_start)
draw_set_valign(fa_top)
draw_set_halign (fa_left)

if talk = 1{
draw_sprite(spr_dialogbox,0,view_xview[0],view_yview[0]+200)
draw_set_color(c_white)
draw_text(view_xview[0], view_yview[0]+200, out)


of course in the first room a lenguaje object
create event
global.language = os_get_language();


and english and spanish objects with this code
press whatever button
global.drawlang = "es" //drawn language modify
init_language() //language init

global.drawlang = "en" //drawn language modify
init_language() //language init

and presto


THE PROBLEM THAT ONLY READS THE FIRST LINE OF THE INI FILE!!!!
For example......
Text1 = This is the first text
again

only "this is the first text" will show up in the dialogue box
but it wil never read "again" since it is in the second line,


please help.......
 
Last edited by a moderator:
T

tavo

Guest
sorry it seems that # does not work when you use .ini text files
 

Yal

🐧 *penguin noises*
GMC Elder
upload_2017-6-14_12-14-24.png
Don't forget poofreading your text :p


One idea would be just using if statements everywhere:
Code:
if(global.language == "en"){
  str1 = "All of your base is belong to us!"
  str2 = "Some other english text"
}
else if(global.language == "es"){
  str1 = "Tous que votre base avons besoin de vous!"//broken french because I don't really know spanish
  str2 = "Un autre texte francais"
}
Gets unwieldy quickly but is the easiest to code.
 
T

tavo

Guest
View attachment 10435
Don't forget poofreading your text :p


One idea would be just using if statements everywhere:
Code:
if(global.language == "en"){
  str1 = "All of your base is belong to us!"
  str2 = "Some other english text"
}
else if(global.language == "es"){
  str1 = "Tous que votre base avons besoin de vous!"//broken french because I don't really know spanish
  str2 = "Un autre texte francais"
}
Gets unwieldy quickly but is the easiest to code.




you gave me an idea instead of using ini files just use global variables to create different boxes(one in english another with the spanish translation)
this is the talk code of my npc
Code:
obj_npc
///step event

if distance_to_object (obj_player) < 4 {


var start = keyboard_check_pressed(vk_space);

if gamepad_is_connected(0){
start = gamepad_button_check_pressed(0,gp_face3);
}

 if (start == true && global.text = false){
 instance_create(x,y, text_box)
 }

 depth = -y
 }

What if I create different text boxes one in english another in spanish and use use global variables something like this

Code:
obj_translation_npc
step event
if distance_to_object (obj_player) < 4 {


var start = keyboard_check_pressed(vk_space);

if gamepad_is_connected(0){
start = gamepad_button_check_pressed(0,gp_face3);
}

 if (start == true && global.text = false){

  if(global_lenguage=="english"){
 instance_create(x,y,obj_text_box_english)
 }
 else{ if(global_lenguage=="spanish"){
 instance_create(x,y,obj_text_spanish)}
 }
 }
 }
of course its giving me errors , I think my else code its totally wrong,
plz help.

thanks in advance




 

RangerX

Member
View attachment 10435
Don't forget poofreading your text :p


One idea would be just using if statements everywhere:
Code:
if(global.language == "en"){
  str1 = "All of your base is belong to us!"
  str2 = "Some other english text"
}
else if(global.language == "es"){
  str1 = "Tous que votre base avons besoin de vous!"//broken french because I don't really know spanish
  str2 = "Un autre texte francais"
}
Gets unwieldy quickly but is the easiest to code.

lol Yal, you made me burst out laughing. Broken French indeed ;)

"All your bases are belong to us" (which is a classic broken English anyways lol) = "Toutes vos bases sont à nous" in proper french.
I don't know if you Google translate it but "Tous que votre base avons besoin de vous" would translate back as "All of your base we need you". hahaha

/off topic
 

Yal

🐧 *penguin noises*
GMC Elder
I actually tried translating it myself (I've had like 7 years' worth of college-level courses in french) .. I guess that shows how little of it stuck :p
(I'm much better at reading french text than writing it, at least)

On topic, though... I don't think having one text box per language is the best solution, unless you have all text rendered as sprites or something... if you have one text box object that can show an arbitrary string, you could just pass different text to it depending on what language is active.
 
T

tavo

Guest
I actually tried translating it myself (I've had like 7 years' worth of college-level courses in french) .. I guess that shows how little of it stuck :p
(I'm much better at reading french text than writing it, at least)

On topic, though... I don't think having one text box per language is the best solution, unless you have all text rendered as sprites or something... if you have one text box object that can show an arbitrary string, you could just pass different text to it depending on what language is active.
THE PROBLEM is that use strings and only reads the first line
Code:
[en]
Text1 = This is the first text
           again
Text2 = This is the second text
Text3 = This is the third text
Text4 = This is the fourth text
Text5 = This is the fifth text



[es]
Text1 = Este es el primer texto
            de nuevo
Text2 = Este es el segundo texto
Text3 = Este es el tercer texto
Text4 = Este es el cuarto texto
Text5 = Este es el quinto texto
it will only appear in the text boxt, "this is the first line" but will never read the second line "again"




this is my translation script
Code:
globalvar TRANS;

TRANS=ds_map_create();
    ini_open("Languages.ini");
//that's where you load the text from the ini file. global.drawlang set, which language you will use. If you modify language, call init_language() again!!!
        TRANS[? "Text1"]=ini_read_string(global.drawlang,"Text1","default");
        TRANS[? "Text2"]=ini_read_string(global.drawlang,"Text2","default");
        TRANS[? "Text3"]=ini_read_string(global.drawlang,"Text3","default");
        TRANS[? "Text4"]=ini_read_string(global.drawlang,"Text4","default");
        TRANS[? "Text5"]=ini_read_string(global.drawlang,"text5","default");
    ini_close();
 
Last edited by a moderator:

chamaeleon

Member
You could try using
Code:
[en]
Text1 = this is the first text\nagain
and
Code:
str = string_replace_all(ini_read_string(global.drawLang, "Text1", "default"), "\\n", "\n");
...
draw_text_ext(xpos, ypos, str, -1, 200);
 

Roderick

Member
Early in the game, during a splash or loading screen, run a script like this:

Code:
enum lang {english, french, spanish, german, russain};

var file[lang.english] = file_text_open_read("english.dat");
var file[lang.french] = file_text_open_read("russian.dat");
var file[lang.spanish] = file_text_open_read("spanish.dat");
var file[lang.german] = file_text_open_read("german.dat");
var file[lang.russain] = file_text_open_read("russian.dat");

var counter = 0;

while (!file_text_eof(file[0])
{
 for (var i = 0; i < 5; i++)
 {
  global.text[i, counter] = file_text_readln(file[i]);
 }
}

for (i = 0; i < 5; i++) {file_text_close(file[i];}
Then, somewhere in the game, set the user's language in a global variable:
Code:
global.current_lang = lang.english;
Whenever you want to draw text, just reference the 2D array you created above. For example, to draw the 200th line of text from your files in the current language:
Code:
draw_text(x, y, global.text[global.current_lang, 200]);
Make sure that all the data files have the exact same number of lines, and that all the text is in the same order, or you could end up showing the wrong text when using certain languages. It will be important to keep a list of line numbers for the specific texts, since you'll just be giving reference numbers to the program.
 
T

tavo

Guest
Early in the game, during a splash or loading screen, run a script like this:

Code:
enum lang {english, french, spanish, german, russain};

var file[lang.english] = file_text_open_read("english.dat");
var file[lang.french] = file_text_open_read("russian.dat");
var file[lang.spanish] = file_text_open_read("spanish.dat");
var file[lang.german] = file_text_open_read("german.dat");
var file[lang.russain] = file_text_open_read("russian.dat");

var counter = 0;

while (!file_text_eof(file[0])
{
 for (var i = 0; i < 5; i++)
 {
  global.text[i, counter] = file_text_readln(file[i]);
 }
}

for (i = 0; i < 5; i++) {file_text_close(file[i];}
Then, somewhere in the game, set the user's language in a global variable:
Code:
global.current_lang = lang.english;
Whenever you want to draw text, just reference the 2D array you created above. For example, to draw the 200th line of text from your files in the current language:
Code:
draw_text(x, y, global.text[global.current_lang, 200]);
Make sure that all the data files have the exact same number of lines, and that all the text is in the same order, or you could end up showing the wrong text when using certain languages. It will be important to keep a list of line numbers for the specific texts, since you'll just be giving reference numbers to the program.
thanks a lot but
I dont have problems in the translation code the problem when you use .ini files
when you have something like this in the creation code
[code
Code:
///create event
text1 = string("   has pasado nuestras defensas# pero jamas venceras# ami nazabot.-3,")
global.text = true
out = string("")
spd = 0

///step event
////hablar
if talk = 1{
out = string_copy (text1,1,spd)
spd +=0.5

////draw event
if talk = 1{
draw_sprite(spr_dialogbox,0,view_xview[0],view_yview[0]+200)
draw_set_color(c_white)
draw_text(view_xview[0], view_yview[0]+200, out)

}
but the problem with ini files extension the code "#" does not work and I want the long dialogue in different lines
 
Last edited by a moderator:

chamaeleon

Member
\but the problem with ini files extension the code "#" does not work and I want the long dialogue in different lines
Try using draw_text_ext() instead of draw_text() to make it wrap lines for # in GM:S 1.4, and \n in GMS 2 (as I did above).
 

Yal

🐧 *penguin noises*
GMC Elder
draw_text_ext() automatically inserts newlines (at preceeding spaces or hyphens) when a word would get partially outside a message box (or some other region boundary you set up) so it sounds perfect for use-cases like this.
 
T

tavo

Guest
draw_text_ext() automatically inserts newlines (at preceeding spaces or hyphens) when a word would get partially outside a message box (or some other region boundary you set up) so it sounds perfect for use-cases like this.
arggggggg draw text ext crash my game
 
T

tavo

Guest
STILL HAVING ERRORS HERE is my original script (ini file)




this is the translation script



This is my text box object
create event


step event





this works fine except as I mentioned before , it cant recognize the "#" code in the ini files and only writes one line of text, Yesterday I have been reading all about draw_text_ext, but I dont get it and all my experiments were a failure,
my game is a very text heavy videogame and I reallly need to solve this trouble.
thanks in advance
 
T

tavo

Guest
draw_text_ext() takes five parameters, not three. Read up on it in the manual to see what the last two does.
thanks a lot chameleon,
according to the manual draw text
draw_text(x, y, string);
my original code that works well with one ini file line
Code:
draw_text(view_xview[0], view_yview[0]+200, out)
according to the manual draw text ext
Description
This function will draw text in a similar way to draw_text only now you can set the space between each line of text - should the text occupy more than one line - and limit the width (in pixels) of the string per line so that should any line exceed this value, GameMaker: Studio will automatically split the text to the next line. A value of -1 for the line separation argument will default to a separation based on the height of the "M" character in the chosen font.
Code:
draw_text_ext(x, y, string, sep, w);
the new parameters....
sep The distance in pixels between lines of text.
w The maximum width in pixels of the string before a line break.

so I try something like this

draw_text_ext(view_xview[0], view_yview[0]+200,3,300);
and totally crashes my game

also tried this
draw_text_ext(view_xview[0],view_yview[0]+200,text1,3,300)
and also totally crashes my game...

sorry chamelon for being such an idiot but I spend hours and hours and cant solve this
 

chamaeleon

Member
Use -1 for sep (as the manual indicates, this results in the separation of lines being calculated based on the height of the letter M in the chosen font). For all I know 300 could be a good maximum width at which GameMaker will automatically wrap text to a new line (totally depends on what your screen is supposed to look like..) If you are experiencing crashes (and not just a compilation failure), I would recommend creating a new project with a single object that has a draw event only that contains draw_text_ext() with the parameters of your choice and see what happens (don't even make use of ini file stuff, just use strings). If you still have issues, that can be dealt with in isolation from all your other code, until it is resolved.
 
T

tavo

Guest
Use -1 for sep (as the manual indicates, this results in the separation of lines being calculated based on the height of the letter M in the chosen font). For all I know 300 could be a good maximum width at which GameMaker will automatically wrap text to a new line (totally depends on what your screen is supposed to look like..) If you are experiencing crashes (and not just a compilation failure), I would recommend creating a new project with a single object that has a draw event only that contains draw_text_ext() with the parameters of your choice and see what happens (don't even make use of ini file stuff, just use strings). If you still have issues, that can be dealt with in isolation from all your other code, until it is resolved.
thanks chamelon at last I did it


my mistake was in the ini file, this is the correct all new different ini file
Code:
[en]
Text1 = This is the first text this more text exe etc because its incredible
Text2 = This is the second text
Text3 = This is the third text
Text4 = This is the fourth text
Text5 = This is the fifth text



[es]
Text1 = Este es el primer texto checando el texto extra para que no digan
Text2 = Este es el segundo texto
Text3 = Este es el tercer texto
Text4 = Este es el cuarto texto
Text5 = Este es el quinto texto

and this is the new improved draw code
Code:
draw_text_ext(view_xview[0],view_yview[0]+200,out, -1, 300);
my mistake was the ini files and I didnt truly understand the draw_text_code well (I barely speak english lol)
and game maker set the lines of text not me,


thanks a lot chameleon :)


(now the hard part is going to be to rewrite all my text boxes text)
 
Top