xovoxx Posted December 18, 2020 Share Posted December 18, 2020 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 More sharing options...
penguin0616 Posted December 18, 2020 Share Posted December 18, 2020 (edited) TheSim:SavePersistentString TheSim:GetPersistentString You can "Find in Files" in DST's code for examples Edited December 18, 2020 by penguin0616 2 Link to comment Share on other sites More sharing options...
xovoxx Posted December 18, 2020 Author Share Posted December 18, 2020 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 end inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 }) inst.components.inspectable:SetDescription("Seems like shinies are his goal. Surely, it would eat gold?") SpawnPrefab("red_mushroomhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) inst.components.eater:SetOnEatFn(OnEatSecondMeal) TheSim:SavePersistentString("meal","1",false,cb)--Save first meal end Do I need some sort of "include"? What am I missing? Thanks in advance! Link to comment Share on other sites More sharing options...
penguin0616 Posted December 18, 2020 Share Posted December 18, 2020 Should actually be SetPersistentString, my bad. 1 Link to comment Share on other sites More sharing options...
xovoxx Posted December 19, 2020 Author Share Posted December 19, 2020 Thank you, that worked! Now I'm at the next step : Getting the persistent string. Here's my code : AddPrefabPostInit("mole", function(inst) TheSim:GetPersistentString("meal", function(load_success, str) if load_success and str == "1" then -- Do stuff end end) end) 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 More sharing options...
penguin0616 Posted December 20, 2020 Share Posted December 20, 2020 (edited) GLOBAL.TheSim Edited December 20, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
xovoxx Posted December 20, 2020 Author Share Posted December 20, 2020 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 More sharing options...
penguin0616 Posted December 20, 2020 Share Posted December 20, 2020 @xovoxx 1. Because some variables are in your environment, some aren't. 2. Maybe tie a specific identifier to each world, and use that to make sure the progress is correct for each save. 1 Link to comment Share on other sites More sharing options...
xovoxx Posted December 22, 2020 Author Share Posted December 22, 2020 Quote 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 More sharing options...
penguin0616 Posted December 22, 2020 Share Posted December 22, 2020 1 hour ago, xovoxx said: Ok. Is there documentation somewhere that would help me find a way to do this? Not that I am aware of, it's something you just do. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now