• 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]Write to text issues

T

ThatJerkKris

Guest
Hello All,

I am currently trying to start a log file for my game for when I want to output some information, I have checked quite a few places now and I cant seem to work out why my game isn't successfully writing to a file and I am hoping someone can help me with this.

If it helps I have tried using the most basic example on game makers documentation for GML and it hasn't worked either, or at the least I am perhaps not understanding how it works as I have checked both the working directory and the projects folders and my logging file isn't created or populated if I create it myself beforehand.

I am wondering if perhaps there is some issue to do with permissions and windows? Something that is perhaps not really going to get mentioned during tutorials, but which may be an issue I am unaware of.

Code:
var file;
file = file_text_open_write(working_directory + "\Logging.txt")
if( file == -1)
{
show_message("Error")
}
show_message(string(working_directory + "\Logging.txt")) 
file_text_write_real(file, 99)
file_text_writeln(file)
file_text_write_string(file, "AI Logging")
file_text_writeln(file)

file_text_close(file)
 
C

Chris

Guest
The first thing I noticed, is that you include a backslash after working_directory, try removing that. The documentation for working_directory indicates that it returns the final backslash, so that might be your issue.
 
T

ThatJerkKris

Guest
I've tried that before, tried it again just in case, still no luck :( Thank you though I wasn't aware it automatically returns a backslash.
 
T

ThatJerkKris

Guest
I solved the issue eventually, posting in case it helps anyone in the future.

When I used:

Code:
show_message(string(working_directory))
I found that I was given the temp folder for game maker at the time, such as:

C:\Users\<yourname>\AppData\Local\Temp\GameMakerStudio2\<yourprojectname>_1B65B7FE\

I found my files were instead outputting to:

C:\Users\<yourname>\AppData\Local\<yourprojectname>\

I'd recommend for anyone like me thinking the text file hasnt been created/added to, to just do a search on their hard drive I guess.
 
Top