Defsave init function in profile throw an error on new profile (SOLVED)

I already use Defsave module by @Pkeod , the module is amazing, but recently I notice that when I delete my save profile, upon starting the game again, the init function on profile throw an error message:

ERROR:SCRIPT: /defsave/profile.lua:43: bad argument #1 to 'inflate' (string expected, got table)
stack traceback:
	[C]: in function 'inflate'
	/defsave/profile.lua:43: in function 'decompress'
	/defsave/profile.lua:198: in function 'init'

I already use it for quite some time, and this issue didn’t happen before. Also, I already try the example_profile on the DefSave github project and It also throw the same error. How do I fix it?

Thanks. :smiley:

There was a bug in the xor obfuscation cipher which I recently fixed in the main module but forget to fix in the profile sub-module but it’s fixed now (it shouldn’t even be in both places but…). Let me know if there are still issues. You might need to delete your save data again if you used the obfuscation helper, shouldn’t need to do that again hopefully.

I’m tired right now so there may be some other obvious issue! I’ll do some tests tomorrow.

1 Like

Thanks for your fast response, but it seems the issue still occur after update the module.
After messing around, my best guess is this issue occur after the commit related with deepcopy for get/set. CMIIW. Nevermind

And have a rest :smile:

I’m new at lua, but after messing around again, I found that change {} to nil in defsave.get function, fix the problem. :thinking:

from this

function M.get(file, key)
	if M.loaded[file] ~= nil then
		if M.loaded[file].data[key] ~= nil then
			local value = clone(M.loaded[file].data[key])
			return value
		else
			return {}
		end
	else
		print("DefSave: Warning when attempting to get a key '" .. key .. "' the file '" .. tostring(file) .. "' could not be found in loaded list")
		return nil
	end
end

into this

function M.get(file, key)
	if M.loaded[file] ~= nil then
		if M.loaded[file].data[key] ~= nil then
			local value = clone(M.loaded[file].data[key])
			return value
		else
			return nil
		end
	else
		print("DefSave: Warning when attempting to get a key '" .. key .. "' the file '" .. tostring(file) .. "' could not be found in loaded list")
		return nil
	end
end

I don’t know the impact on the greater scale, but it does fix the problem.

Please test the master version again. The problem was I think that the decompress function was not checking if the loaded file was a table the first time it loaded. In which case decompressing wouldn’t be necessary.

Yeah, before it was returning nil but I changed it to an empty table when I updated for deepcopy I think. Decompress in the profile extension was only checking for nil and not a table.

Thank you for reporting! Hopefully no other issues for now.

3 Likes

Thanks for your great help. Now the issue is fixed.

2 Likes