Quick answer: Godot file-reading loop missing the last line? eof_reached() goes true after reading past the last byte — classic off-by-one. Read first, then check.
Parsing a CSV file: the last entry is missing in the output. The loop checked eof before reading the next line.
EOF After Read
while not file.eof_reached():
var line = file.get_line()
process(line)Issue: get_line at EOF returns “”, but the loop continues until eof_reached is true. The last real line might be processed, but a phantom empty string also gets processed.
Read-Then-Check
while true:
var line = file.get_line()
if file.eof_reached() and line.is_empty(): break
process(line)Test for end after each read. Handles the “empty last line vs real last line” case.
get_as_text Alternative
For small files, read all at once and split: text.split("\n"). Skips the EOF dance entirely.
Trailing Newline
Files with a trailing newline produce an empty string at the end. Files without one don’t. Your code must handle both consistently.
Verifying
All lines are processed, no missing last entry, no phantom empty entries.
“eof_reached flips after the read. Use read-then-check or get_as_text.”
For config and small data files, prefer JSON parse or get_as_text + split — the line-by-line loop is brittle in too many subtle ways.