LoadState/SaveState Question

Monkey Targets Forums/HTML5/LoadState/SaveState Question

Yoda(Posted 2014) [#1]
If I understand it right, then LoadState/SaveState load/save a file on the server on which my Monkeygame is hosted.

That means, there can be multiple instances of my games running on different users-browsers.

So, what if there's a LoadState/SaveState performed at the same time on different instances? Is that safe? Or should I do it like this in my game, directly one after another, without anything in between?

LoadState - Change State Data - SaveState

As opposed to: At the beginning of the code, LoadState, later modify the State Data, later SaveState?


Soap(Posted 2014) [#2]
You mean the game opened in another browser tab?

You could put a lock on the save per game opening - then read that lock before modifying the state. If the game is opened have it increment the lock number. So if player opens the game two times and both can modify the state have the second load the lock as 1 increment it by 1 and save it by 2, and then the first game open would see that 2 and understand that this situation has occurred, and tell the user to knock it off and that their progress on this tab won't be saved.

The save data is saved locally by the way not on the server unless you code for that! Save data between different browsers should not work at all. If you played in Chrome and again in Firefox or IE or Safari or Opera you would start from a clean save.

Also you shouldn't use savestate for saving your game you should use filesystem functions. Mark only intends save/load state for devices going to and coming back from sleep so use at your own risk.


Yoda(Posted 2014) [#3]
So loadstate/savestate stores data on the users system, not on the server where the game is hosted? Did I understand right?


MikeHart(Posted 2014) [#4]
Yes, you got that right.