0 votes

I want to use the File.seek() function to seek to the beginning of a line in a file. Instead of doing seek(2) and seeking to the third character, I want it to seek to the start of the third line. How do I do something like this?

in Engine by (55 points)
reshown by

1 Answer

0 votes
Best answer

Figured out a way to do it. Not sure if it's the best way, but it's all I can think of:

I pick a random number from 0 to the file's number of lines, then loop from 0 to that number and use the "get_line()" function each time. This brings the cursor to the start of the desired line;

for i in range(0, randi() % lineCount):
    file.get_line()
by (55 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.