0 votes

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.

in Engine by (271 points)

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.

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

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 seekend() 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 seekend() 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

Can you upload that file or post the file content?

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?

1 Answer

0 votes
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)

by (20 points)
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 Frequently asked questions and 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 [email protected] with your username.