About This File

This sample mod provides a file, savable_infinity.lua, which when modimport'ed allows storing correctly the following numerical values as savedata:

  • Plus and minus infinity (i.e., math.huge and -math.huge);
  • NaN (Not a Number, i.e., the result of invalid arithmetical operations, such as 0/0).

The game's save system is patched transparently, so other than modimport'ing savable_infinity.lua no other steps need to be taken: simply feel free to store the above values in savedata.

The patching of the game's DataDumper function uses the fact that Don't Starve's savedata is simply Lua code to store these values as arithmetical expressions: plus infinity is saved as 1/0, negative infinity as -1/0 and NaN as 0/0. The method used for the patching is more hackish than I would like (making heavy use of Lua's debug library), but it is the cleanest method of doing so I could think of, other than simply overriding vanilla's dumper.lua.

The rest of the mode code, beyond savable_infinity.lua, is just a test suite to see the added functionality in action.

The file savable_infinity.lua is modimport'ed in modworldgenmain.lua, so that all savedata is stored correctly (but it can safely be modimport'ed in modmain.lua instead, if worldgen savedata is not a concern).

In modmain.lua, the global variable ENCODE_SAVES is set to false, causing save files to be stored as plain Lua instead of zip compressed Lua, allowing visual inspection of the saves' contents. Furthermore, modmain.lua adds the included infinitysavetest component to the world entity: this component simply returns the mentioned values in its OnSave method and checks the validity of the loaded savedata in its OnLoad method, which prints the following to log.txt:

../mods/SavableInfinity/scripts/components/infinitysavetest.lua(17,1) Running InfinitySaveTest:OnLoad() for [100013 - cave]	../mods/SavableInfinity/scripts/components/infinitysavetest.lua(28,1) Testing savedata entry 'positive infinity'... PASSED	../mods/SavableInfinity/scripts/components/infinitysavetest.lua(28,1) Testing savedata entry 'negative infinity'... PASSED	../mods/SavableInfinity/scripts/components/infinitysavetest.lua(28,1) Testing savedata entry 'NaN'... PASSED	../mods/SavableInfinity/scripts/components/infinitysavetest.lua(30,1) Ran InfinitySaveTest:OnLoad()	


What's New in Version 1.0.3   See changelog

Released

  • Even more modular design.



User Feedback

Recommended Comments

I'm a bit confused....what would this be useful for, beyond maybe viewing save data?

Saving infinity in savedata. Many mods (such as the Link mod) at some place in their development corrupted savedata due to saving infinity. This prevents that kind of savedata corruption, and in fact allows functional saving of infinity (and NaN).

  • Like 1

Share this comment


Link to comment
Share on other sites

So this is used with other mods that tend to crash the game?

 

I'll be honest.... I seen that you posted this, Simplex, and had to see what you cooked up! Just not sure how or why I'd use it! LOL.... Great job anyway!

Share this comment


Link to comment
Share on other sites

So this is used with other mods that tend to crash the game?

 

I'll be honest.... I seen that you posted this, Simplex, and had to see what you cooked up! Just not sure how or why I'd use it! LOL.... Great job anyway!

This is a sample mod, providing a file to be used by other modders. That's why I uploaded it to the "Modding Tools, Tutorials & Examples" category, it's not meant to be used by players.

Share this comment


Link to comment
Share on other sites

Say i start the game with a mod accidentally disabled.If i restart the game before it saves,will the original mod data be preserved?

Share this comment


Link to comment
Share on other sites

Say i start the game with a mod accidentally disabled.If i restart the game before it saves,will the original mod data be preserved?

Yes. This just tweaks how numbers are stored in regular savedata. If you disable the mod and restart the game before it saves, no savedata will be changed. Also, the savedata stored with this mod is compatible with vanilla: it can be loaded even if the mod is disabled.

Share this comment


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