Jump to content

New to LUA, how does serialization work for DontStarve script variables?


seronis
 Share

Recommended Posts

Is serialization of NEW variables I add to any given object to the save file automatic? Do i manually need to edit some save/load routines for custom data?What is best way to serialize data that is meant to be global versus data that is specific to a save game?

Link to comment
Share on other sites

And after two hours of searching in the code before I posted that question.. 5 minutes later I find my own answer *facepalm*

function PlayerProfile:SetValue(name, value)    self.dirty = true    self.persistdata[name] = valueendfunction PlayerProfile:SetSaveSlotValue(idx, name, value)    self.dirty = true    self:SetupSaveSlots()    self.persistdata.save_slots[idx][name] = valueend
This will solve what my actual need was (some new globally available data values). If someone else still has info about the question I asked more knowledge the merrier =-) Edited by seronis
Link to comment
Share on other sites

I asked Kevin (one of the developers) about this generically earlier....he asked that we *NOT* add data to the player profile and saved games files *AT THIS TIME*....mostly out of concern for corrupting players games but also since the game is in beta, the data structures for these files are influx and they need to be able to "upgrade" the files to new formats without worrying about unknown data.

[MENTION=8]Kevin[/MENTION] [MENTION=2]Bigfoot[/MENTION]

Um....I had in mind to ask for this at some point but now that it has come up.....

At some point mods will get sophisticated enough to require data persistance at the player profile and saved game levels and making seperate data files seems onerous and problematic, e.g. multiple platforms, security contexts.

Would it be acceptable for us to store our data under a "mods" section in these files? From there we would index using a unique mod name to access our data and at that level we can use whatever table structure we need.

Then you can just manage the mod data as a "chunk" and leave it up to us to upgrade the format as needed.

Link to comment
Share on other sites

[MENTION=8043]seronis[/MENTION]Using my suggestion would mean that you would need to use the entity uids as an index for instance specific data and have to check that a given id still exists, etc. More error handling essentially.I would hope that we will be able to hook into GameLoad, GameSave, EntSave, EntDelete events to adjust our data as necessary with the new mod loader mechanism.I guess that still does not address completely *new* prefabs, etc but all in do time I guess :DEDIT:Hmm, actually I guess it would because we would have to keep a list of *our* ents based on *our* prefabs which could only be handled if *our* mod was loaded anyways.EDIT2:And just what are you up to anyways!? :D(pm me if you prefer)

Edited by WrathOf
Link to comment
Share on other sites

[MENTION=10271]WrathOf[/MENTION]:I needed to be able to save the number of times the player has died in a given world and the amount of XP already earned to prevent free xp abuse by just suiciding in a game several times.Im also not too worried about the extra data I added. I neither crashed when adding the mod on my local copy nor crashed when removing it (obviously tested this by dying to make sure the relevant section of code was executed).I'll also go add a disclaimer/warning to my mod download page mentioning possible save file load issues during client updates. Wasnt aware there was a potential issue but I dont (yet) understand any way to implement this feature without data persistence.

Link to comment
Share on other sites

[MENTION=8043]seronis[/MENTION]I am not worried about you so much as the developers who are not experienced in dealing with mods for their games. They are on a learning curve here so we need to help, not hinder them so they do not feel the need to back away from supporting it.At this point, only you, the saved game editor guys or I would be crazy enough to mess with the player profile and saved game files.Also, keep in mind the devs are still trying to address why the game keeps inappropriately losing track of saved games and/or deleting them.I dunno, your mod is in the wild now so guess we see how it goes. What do you think of my request for a mods section in the files?EDIT:Luckly, LUA appears to be a rather loose and easy going language for data :D

Edited by WrathOf
Link to comment
Share on other sites

[MENTION=10271]WrathOf[/MENTION]:LUA seems to be 'duck typed' as it is and things are passed to those save routines ignorant of their underlying contents. I would just assume that creative enough use of variable names would be all that is needed. Your 'mod name' can be prefixed to any variable names you create as a modder. With my two values I added I chose variable names long/unique enough I would hope no one else needed to use the same name.Going one step further and just adding categories to the variables (effectively your suggestion of tagging them by a mod name) would also be great and Id love to see that too.Lastly, I havent had the steam version of the game lose my information yet in the past 2 months. Didnt even know this was a known issue. Is this just in the webapp version of the game? I would think peoples usage of privacy plugins would be the cause if it is limited to that. But thats a side effect of not running things as they were intended =-)

Link to comment
Share on other sites

[MENTION=8043]seronis[/MENTION]Lol, this is starting to become a modders chat channel :DTechnically you are correct about the custom variable names in the data structure, I just prefer the segregation of data managed by seperate sources, e.g. devs vs modders.Initially I had issues on steam of it losing track of the saved games even though they were there....had to use the import feature. I think it has to do with running steam in online vs offline mode along with the complication of steam cloud. They added an ini file setting to disable the cloud save so games are saved to the current window's profile. I actually prefer this anyways since it allows other family members to have their own set of saves. Chrome platform....different animal that I am starting to investigate now.Also, keep in mind that they are working on a mac version and eventually a *nix version. Yay!? :S

Link to comment
Share on other sites

Not an issue for me now that I disabled cloud saves....hmm, I think I read somewhere that you would need to delete the profile file *while* the game is running, then close the game to trick steam into thinking the game deleted it and syncs it as such.

Link to comment
Share on other sites

[MENTION=8]Kevin[/MENTION] / [MENTION=2]Bigfoot[/MENTION]

Some additional thoughts on this....

My interest in this is to establish a little bit of framework/protocol under which the modders operate regarding serialized data versus a free-for-all....if for no other reason than to be able to provide the users with useful feedback on the condition of their saved games and you some idea of whether to provide support or defer to the mod developer responsible for the inevitable game crash.

At the moment I am thinking of something along these lines:

t = { ents={ ... }, map = { ... }, playerinfo = { ... }, mods = { mod1 = { info = { ... }, data = { ... }, ents = { ... } }, mod2 = { ... } } }....

where mod1 is a unique name determined by the modder (or maybe not, can't decide yet)

where t.mods.mod1.info = {

displayname = "My Cool Mod",

description = "The mod you just cannot do without",

version = "1.0.0",

warninglevel = 0 | 1 | 2

developer = "MasterModder"

supportlink = "http://forums.kleientertainment.com/showthread.php?...."

}

where warninglevel determines level of requirement for mod to be present and therefore what if any warning to show user if not found, 0 for no warning, 1 for not recommended to proceed may casue corruption, 2 for will cause corruption so mod required

where t.mods.mod1.data is in whatever data format the mod requires.

where t.mods.mod1.ents is a list of ents (these might be loaded by the game after loading the mod or maybe call a standard mod entload function? not sure yet)

The above data would then allow you (or a mod manager we make) to know what mod data is present and where it is coming from to warn the user attempting to load a game if necessary. Also you could "recover" a saved game by easily stripping out the mod data.

Would love to know your thoughts on this when you get a chance....and yes....I know it's crunch time for you guys but addressing this sooner rather than later would be better in the long run.

Or maybe I am all wet and should stop trying to make a mountain out of a mole hill.....tis my nature on occasion. :D

Link to comment
Share on other sites

  • Developer

[MENTION=10271]WrathOf[/MENTION] Agreed re: player-specific data. No worries on the unscheduled features. I'm actually going on holiday in 1.5 weeks, so I basically have 1 week after Tuesday's update to include as much mod-support as I can.

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
 Share

×
  • Create New...