Why is file.get_csv_line() returning an empty pool string array

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

I have the following pair of methods in my game file handler:

func saveHand(deal, state, pressStack, dealNum):
var file = File.new()
var fileName = savePath + "/deal" + str(dealNum) + "-"
fileName += dateTimeStamp() + ".txt"
file.open(fileName, File.WRITE)

var dealPsa
var statePsa
var stackPsa

func retrieveHand(fileName):
var file = File.new()
file.open(fileName, File.READ)
dealPsa = file.get_csv_line() # Get deal psa
statePsa = file.get_csv_line() # Get deal psa
stackPsa = file.get_csv_line() # Get deal psa

The first three arguments to save hand are poolStringArrays and result in the following file:

which, as expected is in the form of thee sets of comma separated values separated by newlines.

However, when retrieveHand(fileName) attempts to read them back dealPsa, statePsa and stackPsa are just three empty poolString arrays. Since the function is called get_csv_line() shouldn’t it fill the PoolStringArrays with the CSV’s in the three lines?

fileName is the name of the file from which the data has been taken, cut and pasted from windows explorer. No errors are thrown. If I print the three variables I just get:

enter code here

:bust_in_silhouette: Reply From: michaelpbl

Never mind. I just answered my own question. I needed to add savePath/ to the filename. What caught me by surprise was that godot didn’t make any demur when I tried to open a non existent path. From now on I better use:

var fileN = savePath + "/" + fileName
    if file.exists(fileN):
         file.open(fileN, File.READ)
         print("Error: Can't find file " + fileN )