Appending to a file instead of overwriting it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mudley
:warning: Old Version Published before Godot 3 was released.

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.

:bust_in_silhouette: Reply From: mollusca

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.

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

Mudley | 2017-05-12 13:22

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.

Xian | 2019-07-01 23:33