Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Medea | |
Old Version | Published before Godot 3 was released. |
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!
What code is being returned by by curr_file.open()
?
avencherus | 2017-10-01 03:54
The return value is 12.
Medea | 2017-10-01 04:31
The failure is at that line then. ERR_FILE_CANT_OPEN = 12
Investigate the file.
avencherus | 2017-10-01 05:10
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!
Medea | 2017-10-01 12:42
Not a problem. These sorts of things happen more often than we would like. X)
avencherus | 2017-10-01 18:05