ID:2375450
 
(See the best response by Nadrew.)

Problem description:

So I've been working on a project for the past couple of days and I've seem to run into a issue.
The map is stored within a global variable `map` and is an associative list full of locations based on `x,y` that link to tiles.

The problem happens when the world is shutting down and the map is needing to be saved, it all works as intended unless you start up another server before the saving is finished, it corrupts the existing map requiring a new one.

TL;DR, How would I go about saving something and making it so the file being saved can't be loaded on a new server while the old server is still processing the save?
Steps of Issue
1. Compile & Run.
2. Close Game (causes the map to save)
3. Start Game Fast (run the game within 0 - 10 seconds)
4. Notice that the map has been corrupted.
5. ???
6. Post a cry for help
Best response
You can use savefile locking. It's in the F1 help.
It doesn't give any examples of it within the reference, could you show me in dm syntax what you mean exactly, sorry.

I have access to very little internet to do any kind of research for any sort of long period of time.
var/savefile/my_save = new()
my_save.Lock(-1)
// Save stuff here
my_save.Unlock()


Now savefile.New() will crash if it's locked, so you'd want to do a try/catch to catch that gracefully.

HOWEVER, creating an instance where one world can boot while the other is saving with the same files is fundamentally bad design in the first place and you should probably reconsider what you're doing that allows it.