system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
starzar |
Python comes with a “a” (Append) flag to append text data to an existing txt/json file(refer).
However, in gdscript such an option is not provided (refer).
Any workarounds ?
system
2
|
|
|
|
Reply From: |
Mindscore |
I would make the following suggestion:
var file = File.new()
var path = "user://example.txt"
if file.file_exists(path):
file.open(path, File.READ_WRITE)
file.seek_end()
else:
file.open(path, File.WRITE)
# append lines to file
file.store_line("example")
file.close()
You can obviously shorten the code when you are sure that the file already exists.
The key method here is seek_end()