How does GDscript look for the end of the file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Xian

I used

file.seek_end()
print(file.eof_reached())

it didn’t work, it returns false, and then I used seek() and while to find the end of the file, but the became an endless loop. Basically, I am asking what special character does it consider to be the delimiter or symbol that it is the end of the file.

I think it relies on the C API for files ( http://www.cplusplus.com/reference/cstdio/fgetc/ ), which is supposed to return EOF when an attempt to read past the end of the file is made. seek_end() goes to the end, but does not perform a read, so… I’m not sure wether this is a bug or not.

Zylann | 2019-07-02 00:18

Are you trying to stop reading a file inside a loop?

Dlean Jeans | 2019-07-02 03:58

i wanted to reach the end of the file. But it wasn’t working so i tried use a loop to move the cursor all the way to end of the file, but it resulted in a endless loop. This could only mean that there is no special character that acts as a delimiter for my file, which is why when i used seek_end() it didn’t work because it couldn’t find the delimiter character, same reason why using the loop resulted in an endless loop, because it couldn’t find that delimiter and resulted in reading beyond the original file, which could also mean my saving to file function is lacking. Which is why I am asking how seek_end() works so that I can add a delimiter.

P.S. I tried the c or c++ delimiter which is “\0”

file.store_line("\0")

this resulted in an error

Xian | 2019-07-02 05:38

Can you upload that file or post the file content?

Dlean Jeans | 2019-07-02 17:49

it was

(14:49:22) : test

i pre-appended a time to my text i wanted to store in my file. Guys thank for all your help for some reason after my project was removed from godot and re-added it the function runs properly and will search to the end now.

(14:49:37) : test
(14:50:8) : test

Promise no changes whatsoever. It just runs properly all of a sudden xD? I have no idea what happened. above u can see 2 lines it shows i was able to append.
I could explain how it happened. Yesterday afternoon I ran godot in my pc and it crashed instead of running. And so i used task manager to close it run it again. after which i noticed my project file was no longer in the list so i imported it back(it wasn’t deleted). Afterwards I check for bugs but everything was the same so I ran the project only to find out it works now? I swear I have absolutely no idea what in the world just happened xD?

Xian | 2019-07-02 21:55

:bust_in_silhouette: Reply From: PeterPM
var file = File.new()
file.open("user://teste.teste", File.READ_WRITE)
file.seek_end(0)

will put you on the end of the file

(you need READ to perform the evaluation, otherwhise it will just put a corrupted char on the file)