Import CSV file at runtime error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Varven

Hi,
i have a “database” written in CSV file. I want to import the data form this file when i run the game. Everything is fine when im debugging game in Godot Editor, but when i try to run exported game im getting an error: ‘File must be opened before use’. It seems like the exported version of the game cannot load/find CSV file.

func LOAD_UPGRADES():
var file = File.new()
var err = file.open("res://upgrades.csv", file.READ)
if err != 0:
	printerr("[ERROR] Object: File (error code: ", err , ")")
	get_tree().quit()
while !file.eof_reached():
	var csv_line = file.get_csv_line()
	if csv_line.size() == 5:
		upgrades.append(apply_upgrade(csv_line))
file.close()
print("[INFO]: Upgrades amount: ", upgrades.size())

I tried with changing a path to “./upgrades.csv” but i got the same error. I cannot use “user://” directory because i have data to import.

It is any solution to this problem? I don’t want to insert 3000 of variables via code.