• 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!

GameMaker Getting Japanese text from a a txt file.

Kyrieru

Member
Following some advice I was able to read from a .txt file and get a dialogue system working with english.
Code:
if file_exists(path+file)
{
read = file_text_open_read(path+file);
var num = 0;
while (!file_text_eof(read))
{
str[num++] = file_text_read_string(read);
message[num] = ""
file_text_readln(read); 
}
file_text_close(read);
}
However, even after adding character ranges to the font, getting japanese text from a file returns □□□□□□□


Yet, if I just write something directly like this,

Code:
draw_text(x,y,"かなづかい")
It displays it correctly, using the same font.
What string functions would cause the text to get messed up?
 

FrostyCat

Redemption Seeker
It's the way you saved the text file that got you messed up.

When you save text containing material outside the 7-bit ASCII range, make sure you set the encoding to UTF-8. That's the safe bet for most European languages aside from English, and your only safe bet for non-Latin scripts. On Notepad this is configured on the Save window. On others like Atom, Notepad++ or Sublime, you will see a dedicated menu for this.

In whatever form this functionality takes, what it does is adding a short header to the file signalling that it contains UTF-8 content, with the bytes 0xEF, 0xBB, 0xBF in order. This is called the byte-order marker, or BOM for short. It tells compliant readers (the GMS file_text_*() function set is one of them) that UTF-8 tricks are employed ahead and the bytes that go above 0x7F are not to be taken alone. Failing this would give you the nonsense characters that crop up when bytes containing UTF-8 tricks are taken at an isolated face value instead of in combination with adjacent bytes.
 
Top