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

[SOLVED] Empty .txt File (file_text_open)

L

LWDIV

Guest
Hello, i can read from a .txt file located in "C:\Users\LWDIV\Documents\GameMakerStudio2\sprite to formation_array\datafiles" but i cannot write into that file. I found out that GML is creating temp folders located here "C:\Users\LWDIV\AppData\Local\GameMakerStudio2\GMS2TEMP" . Even here the .txt file is empty.

My Code is running without any errors.

Code for read (working):
var f, line;
f = file_text_open_read(working_directory + "/test.txt");
if (f != -1) {
line = file_text_read_string(f);
show_message(line);
}

Code for write (not working):
var f, line;
f = file_text_open_write(working_directory + "/test.txt");
if (f != -1) {
show_message("blubb"); //testing if the code gets into the if-statement (works!)
line = "das ist ein test";
file_text_write_string(f, line);
}

file_text_close(f);

I used google over 3 hours now but cannot find a solution.
What do i wrong?
 
First thing you could try is to remove the forward slash "/" from your string, because the variable working_directory already includes it.

e.g.
Code:
f = file_text_open_write(working_directory + "test.txt");
Second, don't use working_directory at all.

Code:
f = file_text_open_write("test.txt");
working_directory can point to different places depending on how you use it.

Just specifying the file name should always read and write to the location of %LOCALAPPDATA%/<gamedir>/ windows path.

By default this location will be : C:/Users/<User Name>/AppData/Local/<Game Name>
 
L

LWDIV

Guest
By default this location will be : C:/Users/<User Name>/AppData/Local/<Game Name>
Thank you! I was looking at C:\Users\LWDIV\AppData\Local\GameMakerStudio2\GMS2TEMP .. as you said i found my game name (folder) at C:\Users\LWDIV\AppData\Local\sprite_to_formation_array. It worked! You helped me now the second time ;)

But it is confusing to have like 3 times the file in 3 different locations :/
 
Thank you! I was looking at C:\Users\LWDIV\AppData\Local\GameMakerStudio2\GMS2TEMP .. as you said i found my game name (folder) at C:\Users\LWDIV\AppData\Local\sprite_to_formation_array. It worked! You helped me now the second time ;)

But it is confusing to have like 3 times the file in 3 different locations :/
Yeah, it was confusing for me at first too, needed to read the manual entry on File Systems and do a few tests myself before I became familiar with it.
 
Top