Jump to content

How to save my mod data for future sessions?

Recommended Posts

Hello all,

I am making a mod where players can "progress" by feeding a character. I got the progression down and working great, with lots of help from the nice people of this forum!

However, while testing my mod, I realize that if the server is shut down and restarted, all "progress" is lost.

I'm looking for a way to save the status of the fed character, so that players don't have to start over if they take a break.

Thank you!

Link to comment
Share on other sites

Thank you for the fast reply!

However, there seems to be something I don't understand.

I get the error "attempt to call method 'SavePersistentString' (a nil value)". Looking at DST's code, it looks like I'm using the function alright... so there's definitely something I don't understand. 

Here's my function :

local function OnEatFirstMeal(inst)
	local cb = function()
		--Do nothing
    inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 })
	inst.components.inspectable:SetDescription("Seems like shinies are his goal. Surely, it would eat gold?")
	TheSim:SavePersistentString("meal","1",false,cb)--Save first meal

Do I need some sort of "include"? What am I missing?

Thanks in advance!

Link to comment
Share on other sites

Thank you, that worked!

Now I'm at the next step : Getting the persistent string.

Here's my code

AddPrefabPostInit("mole", function(inst)
			function(load_success, str)
				if load_success and str == "1" then
					-- Do stuff

For some reason, whenever I resume an existing server, my mod crashes during the loading with the error : 

attempt to index global 'TheSim' (a nil value)

On the second line of my function. This occurs regardless of the "meal" persistent string existing or not.

I checked and double checked my syntax : it looks like it's fine. Is it because I can't call "TheSim" during the PostInit?

Thanks again for all the help!

Link to comment
Share on other sites

That worked!

but that raises two questions : 

1. Why do I sometimes need to call "Global" before "TheSim", and sometimes I don't need to?

2. The persistent string is saved across games. So even if I erase my game and start a new one, my progress remains. How can I prevent this?

Thanks a lot for the help as always!

Link to comment
Share on other sites


Maybe tie a specific identifier to each world, and use that to make sure the progress is correct for each save.

Ok. Is there documentation somewhere that would help me find a way to do this?

I feel like if I could access the game's name, and/or the eater instance's ID, I could make it a part of the string and basically make my persistent string related to that specific game.

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...