0 votes

I'm trying to read in a list of names from a text file into an Array using this code:

var sector_names = []
const sector_names_path = "res://sector_names.txt"

var curr_file = File.new()
curr_file.open(sector_names_path, curr_file.READ)
while (!curr_file.eof_reached()):
    sector_names.append(curr_file.get_line())
curr_file.close()

However, this fails to actually read any data and instead generates an infinite series of errors:

ERROR: _File::eof_reached: Condition ' !f ' is true. returned: false
   At: core\bind\core_bind.cpp:1493
ERROR: _File::get_line: Condition ' !f ' is true. returned: String()
   At: core\bind\core_bind.cpp:1588
ERROR: _File::eof_reached: Condition ' !f ' is true. returned: false
   At: core\bind\core_bind.cpp:1493
ERROR: _File::get_line: Condition ' !f ' is true. returned: String()
   At: core\bind\core_bind.cpp:1588

The sector_names.txt file is in the root folder of the project, the same folder the script is in. I'm loading the script as a singleton - maybe that has something to do with it? I'm running Godot v2.1.4stable on a Windows 10 machine, and all my Godot files, including the Godot application itself, are on an external HDD.

Since I'm new to Godot, I suspect this is the result of a mistake on my part. Any advice would be appreciated!

in Engine by (12 points)

What code is being returned by by curr_file.open()?

The return value is 12.

The failure is at that line then. ERR_FILE_CANT_OPEN = 12

Investigate the file.

Okay, I've found out what was going on. As expected, it's a silly thing on my part.

I recently got a new PC, and hadn't set Windows Explorer to show all file extensions. So the files I was creating had an extra ".txt" on the end of their filenames that wasn't showing up in Explorer. I removed those extensions, and now everything works as expected.

Thanks for your insights!

Not a problem. These sorts of things happen more often than we would like. X)

Please log in or register to answer this question.

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.