ID:151916
 
something stupid meby, but i like to ask

if i send host file to someone and he run my server and same players save thier charather there.
if i change my code and send him the new host files, thier save will stay or will delete?


It will stay, but if you've changed how you use savefiles (for instance, you save different stuff) the host is likely to get errors and may want to manually delete the savefiles.
In response to Stephen001
I normaly add a version number ("savefile_version") to the savefile and check that before loading it. if the version is out of date tell the user that sadly their savefile can not be used.
In response to Madpeter1231
A pretty common, and quite sensible tactic.
In response to Madpeter1231
You could also make a simple function to convert the savefile data to the new format you are using. Then it doesn't matter what happens, everything always works and is compatible.

It also makes you look cooler and get more kudos from your playerbase when they instead see an alert that says "Please wait; your savefile version is outdated and is being converted." Realistically, it would happen in about the amount of time it takes their brain to notice that an alert has even popped up at all, but it still looks good on your part.
In response to Loduwijk
Savefile compatibility in BYOND has its drawbacks, though.

1) Loading any object type from a savefile that no longer exists in the code produces a runtime error. This cannot be avoided without leaving an obsolete prototype within the code.

E.g., if I have a /obj/weapon/promo_sword_of_death and I award that to the first 30 people who join the game (natch this is a stupid idea, but just for sake of example), and their inventories are saved to file, I cannot remove the /obj/weapon/promo_sword_of_death object from the game without breaking savefile compatibility. What I *can* do is leave the /obj/weapon/promo_sword_of_death in the game, and add the snippet:
obj/weapon/promo_sword_of_death/New()
del src

to clean them up from anyone who loads the game with one included. Sadly, you'll have to leave this in the game permanently unless you're absolutely certain that all players attached to the game have loaded their savefiles.

You could also write a utility to loop through the saves, load their characters, delete the item, then re-save them, which you'd execute once as a maintenance operation. Then you could safely delete the offending object type.

2) Directly loading an object from a savefile that still exists, but was saved with variables that no longer exist, will also cause a runtime error. This is a similar problem to the one above, but slightly less easy to fix.

The utility program to fix this would be to load all of the savefiles (while still having the variable defined in the code), then execute <code>variable = initial(variable)</code> on all of them and re-saving. Then the savefiles would be compatible.


In short, BYOND's savefile compatibility can be tough for a changing project. Consider writing utilities to update all of the savefiles manually instead of leaving vestiges in your code.

The other strategy is to save variables by key and value, e.g., <code>F["variable"] = src.variable</code>, instead of directly writing the object to file. Then you just remove the relevant line of code when you no longer use that variable, and it'll leave a "dead key" in the save file that doesn't hurt anything. (Sort of like those dull single brass keys you find while walking. You'll never know what door they go to, just that the key exists, and you can just ignore it.)