The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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)
file.store_csv_line(deal)
file.store_csv_line(state)
file.store_csv_line(pressStack) 
file.close()

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:
9C,AS,6H,9H,6D,10S,8C,2C,9S,3H,4S,10C,3S,2D,AD,7H,5H,QS,3D,KC,JS,8D,4H,10H,KD,2H,QH,QD,5S,AH,JD,6C,4C,KS,10D,7C,JC,QC,9D,7S,5D,2S,KH,4D,JH,7D,3C,5C,8S,6S,8H,AC
1500,20,10,True,False,False,False,False,Sean,,2,0,0,1,True,False,False,False,False,True,True,Michael,1500,1500,0,False,2,True,False,False,False,False,True,True,Cullam,1500,1500,0,False,3,True,True,False,False,True,True,True,Sean,1500,1500,0,False,4,True,False,False,False,False,True,True,Glenn,1500,1500,0,False,5,True,False,False,False,False,True,True,Clyde,1500,1500,0,False,3,4
Deal,Sean,True,0,see,Michael,False,0,raise,Cullam,False,80,fold,Sean,False,0,see,Glenn,False,0,see,Clyde,False,0,see,Michael,False,0,Flop,Sean,True,0,check,Glenn,False,0,check,Clyde,False,0,raise,Michael,False,100,see,Cullam,False,0,fold,Glenn,False,0,fold,Clyde,False,0,Turn,Sean,True,0,check,Michael,False,0,check,Cullam,False,0,River,Sean,True,0,check,Michael,False,0,check,Cullam,False,0,Value,Sean,True,0

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 getcsvline() 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

in Engine by (38 points)

1 Answer

+1 vote

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)
    else:
         print("Error: Can't find file " + fileN )
by (38 points)
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.