No folder for sys.get_save_file (SOLVED)

I’m trying to save a file with filename = sys.get_save_file(“MyGame”, “profile” … profileN) and … “/chars.json”, prof.character), but somehow it doesn’t work if there’s no folder created before it. It creates only “MyGame” folder and then gives an error Could not write to the file C:\Users…\AppData\Roaming\MyGame\profile1/chars.json.

How can i fix that?

Tested on Win8 and Win7.

Thank you!

This is what I use and it works:


local M = {}

local path = sys.get_save_file(string.gsub(sys.get_config('project.title'), '%s+', ''), 'data')
local loaded = sys.load(path)

M.table = 
    highscore = loaded.highscore or 0,
    mytable = mytable or {}

function, M.table)

return M
1 Like

Thanks! Just got it. The problem was in that slash sign in Changed to … “chars.json”, prof.character) and it works.

1 Like

Also remember to set a default value for each key otherwise if you want to use it later in your game and want to compare things with your save data then you might get an error like: 'Attempt to compare a nil value’

1 Like

Yes, you tried to create a subfolder. The function creates a file name located in the “MyGame”.

1 Like

dev.dashplay Sry. Not sure which key you mean. =)

Mathias_WesterdahlDefold team Can I create subfolders in runtime?

I don’t think you can using sys.get_save_file() no. Perhaps using the Lua io module?
What’s the use case/benefit of having multiple folders in the app folder?

1 Like

Well, guess we’ll figure it out later. Now I’m super happy that we’ve made a solid demo from scratch in just a 3 months. Absolutely astonishing results with Defold. =)

1 Like

I still need subfolders. Is there any api that I can use to create subfolders?

LFS Extension: GitHub - britzl/defold-lfs: LuaFileSystem port to a Defold native extension

I also built a library for saving and loading data and auto-building subfolder paths, so I could share that if needed.


Thanks, right now I just want it to create a subfolder for caching files