When i try a insert new line using store_line(), it causes the next line (in case of this screenshot, line 1 hello) get the initial letters removed and i'm trying to make it insert a new line without affect the next line
#store_line() causing next line's text characters getting removed
1 messages · Page 1 of 1 (latest)
you override position 1 with h, two with linebreak, so ofc you're missing 2 characters of hello… the content does not just get shifted
i see
is there a function of FileAccess that appends a new line instead of override?
that's not how file systems are designed to work. You can read it into memory, modify it, write it. If your file is too big for memory you'll have to work with buffers or use piping on your OS to let it handle the details
that's not how file systems are designed to work
You are very wrong with this statement.
Obviously files can be appended, otherwise most things on your computer wouldn't even work.
You could do seek_end(): https://docs.godotengine.org/en/stable/classes/class_fileaccess.html#class-fileaccess-method-seek-end
Godot Engine documentation
Inherits: RefCounted< Object Provides methods for file reading and writing operations. Description: This class can be used to permanently store data in the user device's file system and to read fro...
To put the cursor at the end, and then write your data.
Here's a python (close to GDscript) example: https://docs.python.org/3/library/functions.html#open
Mode a stands for append, putting the cursor at the end.
yes but not at the front
cat test.txt
world
sed -i '1ihello' test.txt
cat test.txt
hello
world```
just did this on the command line 😛
I'm not arguing that you can change files, just that you can't append files in the way that you just write the few bytes you wanna insert and be done with it... that's not how the filesystem works
But that's exactly how filesystems work.
you can append at the end and get away with writing the few bytes, but if you wanna change the start, you have to rewrite everything
believe what you want
But that happens internally, you dont need to worry about that
Just like if you open a text file in whatever editor, and you put in a new word at the start, yes, the whole doc gets (re)written to disk. But that doesn't matter, as in, who cares what happens under the hood.
If, as a user/dev/player/whatever, I need to write hello in front of world, I can do that. As a user, I'm not going to care/worry about what happens on the disk itself. As long as in the end it says hello world, you're good to go.
It's not like you're manually flipping bits with a tiny magnet to put hello world on disk. 🙄
just read my responses, it's not like you're disagreeing with anything I said
I found a workaround based on string split (which where i use to write the file using this)
btw, thanks for the suggestion
func add_new_line(text: String, line: int, ref: String) -> String:
var ref_split = ref.split("\n")
ref_split.insert(max(line - 1, 0), text)
var final: String
final = "\n".join(ref_split)
return final
I just mentioned the typical godot fileaccess possibilities (read all, modify in godot, write all or use get_buffer set_buffer) to achieve the modification, because OP probably does not want to accommodate every target OS' terminal solutions to do this task