Jump to content

Help saveing and loading data

Recommended Posts

Whats the best way to save and load data that is being displayed on the hud?

Ive created a widget that shows a list of strings entered by the player on the side of the hud, but when you exit and come back its gone.

I looked into some ways other mods do it and the game uses methods like TheSim:SetPersistentString
or SavePersistentString and for components OnSave/OnLoad. But everything I've searched doesn't explain this well enough for me to implement confidently.

Can anyone lend me some help? Many thanks in advance!

Here what I've got so far.


function nameList:GetSaveName()
	local saveName = "nameList" .. Compatibility:TheWorld().meta.seed
	if Compatibility:TheWorld():HasTag("cave") then
		saveName = saveName .. "C"
	return saveName

function nameList:Load()
	TheSim:GetPersistentString(self:GetSameName(), function(load_success, data)
		if load_success then
			self.persistdata = json.decode(data)
	end, false)

function nameList:Save(callback)
	local data = json.encode(self.persistdata)
	local insz, outsz = SavePersistentString(self:GetSameName(), data, ENCODE_SAVES, callback)



Edited by OneNineTwo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...