GMS 2 Empty Boxes at newline locations after converting a txt file to string

Hi everybody. I'm stumped on this one. I've been messing around with it for about an hour now, and I just can't figure out what this character is that keeps appearing at the end of a line after converting a txt file of dialogue to a string to use inside the game.

I wrote this function to return an included txt file as a string:
Code:
///@desc this converts a file to string
///@argument0 filename
var i, file, str;
str=""

i = 0;
file = file_text_open_read(working_directory + argument0);
while (!file_text_eof(file))
    {
    str+= file_text_readln(file);
    }
file_text_close(file);
return str;
There are no errors and the game doesn't crash, or anything, but I get this weird box character wherever there is a new line in the original txt file.

If the original file looks like this:
Code:
This is the original file!

This is another line on the file!
The returned string would output like this:
Code:
This is the original file!▯
▯
This is another line on the file!
I've tried using
Code:
str = string_replace(str,"▯","");
with all sorts of variations for any Unicode character that vaguely looks like an empty rectangle, but it doesn't get rid of it.

Any help with this would be amazing, thanks.
 

rIKmAN

Member
Any help with this would be amazing, thanks.
The Strings section of the manual contains the following info:
Another thing to note is that the unicode character 9647 (▯) is used to substitute any missing glyphs that you may have in your designated font when rendering it in the draw event. So if your font doesn't have, for example, the ° symbol, then writing 90° will actually produce 90▯.
What editor are you using to save the text files, seems like it's possibly adding data to the end of lines that is being interpreted as a missing glyph?

Also a couple of search results from a quick Google that may be helpful:

1) https://forum.yoyogames.com/index.php?threads/replace-▯-with-something-else.59540/
2) https://forum.yoyogames.com/index.php?threads/how-do-i-remove-▯-blank-space-when-my-game-runs.63310/
 
Last edited:
The Strings section of the manual contains the following info:


What editor are you using to save the text files, seems like it's possibly adding data to the end of lines that is being interpreted as a missing glyph?

Also a couple of search results from a quick Google that may be helpful:

1) https://forum.yoyogames.com/index.php?threads/replace-▯-with-something-else.59540/
2) https://forum.yoyogames.com/index.php?threads/how-do-i-remove-▯-blank-space-when-my-game-runs.63310/

Thanks for responding, I figured it had something to do with a missing glyph. I am using notepad as an editor, is there a text editor you know of that wouldn't add any extra data like that to the end of a line?
 

TsukaYuriko

🌠
Forum Staff
Moderator
Try file_text_read_string in place of the file_text_readln shortcut? Not sure why it would, but the latter may be returning a new line character (as it not only reads the line, but also skips to the next).

Did you by any chance save these text files on a different operating system? There are differences between OSes regarding which characters are used as the new line character(s) that may bite you in the back here.

Try to open the file in, say, Notepad++ and turn on the display of special characters. That way, you should be able to see if there are any characters at the end of lines where they shouldn't be. While you're there, also check the encoding of the files and ensure that it's UTF-8.
 
Try file_text_read_string in place of the file_text_readln shortcut? Not sure why it would, but the latter may be returning a new line character (as it not only reads the line, but also skips to the next).

Did you by any chance save these text files on a different operating system? There are differences between OSes regarding which characters are used as the new line character(s) that may bite you in the back here.

Try to open the file in, say, Notepad++ and turn on the display of special characters. That way, you should be able to see if there are any characters at the end of lines where they shouldn't be. While you're there, also check the encoding of the files and ensure that it's UTF-8.
Yep, that works perfectly!
Here's the code:
Code:
///@desc this converts a file to string
///@argument0 filename
var file, str;
str=""
file = file_text_open_read(working_directory + argument0);
while (!file_text_eof(file))
    {
    str+=file_text_read_string(file)+"\n";
    file_text_readln(file);
    }
file_text_close(file);
return str;
 
Top