+2 votes

I'm making a logger script for my game, with a function that when is called, opens the log file, inserts the log text, and then closes it.

But I have run into a problem. Each time the new text overwrites the old one, so I would like to know how to append to the file instead.

in Engine by (60 points)

1 Answer

+6 votes
Best answer

Open the file with mode READ_WRITE, seek to the end with seek_end(), optionally insert a newline with store_string("\n") and write your log text.

by (1,554 points)
selected by

I was so close then! I did exactly that but just in WRITE mode.

if your using windows and your file is read in notepad like me, ("\n") will not work, so you should use ("\r"). That much is what I know, regarding seek_end(), it doesn't seem to go to the end of my file. It just stays in the beginning. I'll update this when I got the chance to understand why.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.