0 votes

Hi every one,
I made my first game and wrote the below functions to read and write the game date

func fDict2JsonFile(dictIn:Dictionary,fileName:String=gMainFileName)->bool:
var file = File.new()
if file.open(fileName,File.WRITE)!=0:
    print("Error opening file")
    return false
file.store_line(to_json(dictIn))
file.close()
return true

func fReadJson2Dict(matchName:String="",seekNo:int=-1,fileName:String=gMainFileName)->Dictionary:
var file = File.new()
if !file.file_exists(fileName) || file.open(fileName, File.READ) != 0:
    return {}
if matchName.empty():
    return parse_json(file.get_line())
if seekNo!=-1:
    file.seek(seekNo)
    var line=parse_json(file.get_line())
    if fFileLineCheck(line,matchName,file): return line
else:
    while file.get_position() < file.get_len():
        var line=parse_json(file.get_line())
        if fFileLineCheck(line,matchName,file): return line
file.close()
return {}

read and write work correct when I'm in Godot, I mean when in programming and use F5 key...
but when I export a game, read and write not work in Linux, Android, and Windows platforms.
shall I consider any extra issue to serve this? is it a bug?
many thanks

Godot version 3.2.3
in Engine by (27 points)

1 Answer

+1 vote
Best answer

When you building your game, you need to add custom files to export. This is done in Project -> Export -> Select preset you want to export -> Open Resources tab and add *.json (if your configs have .json extension) to filters to export non-resource files/folders.

by (1,116 points)
selected by

thanks,I use this user://gamedata.db, is it should be known file type?

Export only affects files in res:// folders. So it is not the case. Then, instead of if file.open(fileName,File.WRITE)!=0: try to save error code and print it to see what's wrong.

error = file.open(fileName,File.WRITE)
if error!=0:
    print("Failed to open file, error code: %d" % error)

Descriptions of error codes can be found here https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#enum-globalscope-error

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 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 webmaster@godotengine.org with your username.