GML [SOLVED] No content is read on an existing text file.

V

volky

Guest
I am using a simple code to read the following file after pressing F11. The file is already imported into included files and exists in the working directory.

GML:
q = file_text_open_read("room2.txt");
s = file_text_read_string(q);
show_message("!"+s+"! " + string(file_exists("room2.txt")));
if (s == "") { show_message("oops"); }

file_text_close(q);
This is how the results looks like when I press F11:

Capture.PNG

Any ideas what I am doing wrong? The file is not empty and has some text in it: "%test,300,300,90".
 

kburkhart84

Firehammer Games
Try debugging, show the contents of just the s variable, just to see what it is. It is not empty I'm guessing since you didn't show us that you got the "oops" message though the code is there. Or maybe it is empty but you didn't mention that...I don't know.

Also, just to be sure, are you sure that the text file has those contents? If you added an empty text file originally, and then updated the one you have outside the IDE with that content, the one in the IDE won't get said content. You have to re-import it(this is different from the newer 2.3 releases).
 
V

volky

Guest
Thanks for the quick answer. variable s is also empty, I just did not show it. What I now tried is to clean the target, delete the datafile called "room2.txt" and re-import it. Then added a breakpoint to see the values:


1613665140041.png
Is it also normal that the q is 1?
 

chamaeleon

Member
What do you get if you do
GML:
var fp = file_bin_open("room2.txt");
show_debug_message("File size = " + string(file_bin_size(fp));
file_bin_close(fp);
 
V

volky

Guest
Thanks. The output was zero, then I checked where it might save the files to. Apparently as previous answer said:

If you added an empty text file originally, and then updated the one you have outside the IDE with that content, the one in the IDE won't get said content. You have to re-import it(this is different from the newer 2.3 releases).
There was an empty file with the same name, and GM did not update that file.
 

kburkhart84

Firehammer Games
Is it also normal that the q is 1?
q is fine as 1. It is just a file handle so as long as it isn't 0 you are fine.

There was an empty file with the same name, and GM did not update that file.
I had suspected that might be it. Up until recently, you had to manually re-import any files you had in the included files stuff if you needed any changes made. It was a massive pain. Starting with version 2.3(not even 2.0, but 2.3), Included files works differently. There is now a "datafiles" folder in the project folder. Any files you put in there are simply automatically added as "included files." Any updates/changes are therefore automatically included, as they aren't really imported in the IDE anymore. And now, the only thing in the IDE about them involves simply include/exclude checkmarks for different platforms. There is no more need to do much of anything in the IDE unless you include something that you don't want sent to the game builds.
 
Top