![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Xian |
I want to make a function that will save data onto a file within a designated file path.
The function being
static func writeToFile(data, filePath, fileName):
if (getDataType(fileName) == "string"):
var file = File.new()
if (getDataType(filePath) == "string"):
if file.open("user://"+filePath+fileName, File.WRITE) != 0:
print("Error opening file")
return
else:
if file.open("user://"+fileName, File.WRITE) != 0:
print("Error opening file")
return
return
file.store_line(data)
file.close()
return
getDataType() is a function i made to return a string to classify what type of data is it.
Anyways, the result is that it only works if there is no filePath being added. I have a feeling this might not work if the desired folder/path doesn’t exist. For that reason, I would like to ask if there is a way to make folders or even zips using gdscripts. If there isn’t then is it possible with nativeScript? I heard godot can use c++,
while I do know you can do that whole file saving, making folders and so on using c++, I have no clue to what extent c++ is capable of in godot.
As for why I am doing this, it is because I am making a voxel game like minecraft or 7 days to day. You can’t just save your saved game in saveGame.sav file. Voxels need actual folders to store save games and chunk files. Because saving everything in a single file makes file reading and file saving slow since data is will be add and read sequentially so it saves a lot of process speed if the chunks are stored in separate files. This is the same reason minecraft also stores chunks separately
Xian | 2019-07-01 11:24