No folder for sys.get_save_file (SOLVED)

#1

I’m trying to save a file with filename = sys.get_save_file(“MyGame”, “profile” … profileN) and sys.save(filename … “/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!

0 Likes

#2

This is what I use and it works:

A LUA MODULE:

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.save()
    sys.save(path, M.table)
end

return M
1 Like

#3

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

1 Like

#4

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

#5

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

1 Like

#6

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

Mathias_WesterdahlDefold team Can I create subfolders in runtime?

0 Likes

#7

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

#8

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