Serious Sam 4

Serious Sam 4

Not enough ratings
Save & Load Script Functions Handler
   
Award
Favorite
Favorited
Unfavorite
Type: Additions
File Size
Posted
Updated
83.276 KB
21 Sep, 2021 @ 8:42am
21 Sep, 2021 @ 10:59am
3 Change Notes ( view )

Subscribe to download
Save & Load Script Functions Handler

Description
[MODDING RESOURCE]

This mod allows to call functions on saving game and load a savegame. While you actually can do that on your own, the mod allows you to wrap your functions inside already handled callbacks, bringing compatibility with other mods which make use of it.

There are several new functions, each stored in worldGlobals table.
Function
Arguments
Returns
Description
AddSaveGameCallback
name, function
nil
Saves given function under given name into list of functions which will be called before a savegame is created.
AddLoadGameCallback
name, function
nil
Saves given function under given name into list of functions which will be called when a savegame is loaded.
RemoveSaveGameCallback
name
nil
Deletes a function under given name from list of functions which will be called before a savegame is created.
RemoveLoadGameCallback
name
nil
Deletes a function under given name from list of functions which will be called when a savegame is loaded.
DoesSaveGameCallbackExist
name
bool
Checks whether function with given name exists in save game functions list.
DoesLoadGameCallbackExist
name
bool
Checks whether function with given name exists in load game functions list.

There is also a worldGlobals.SaveLoadHandler_bInitialized flag, intended to be used to assure that the mod was initialized.

Example code:
-- assure SaveLoadHandler has its functions declared while not worldGlobals.SaveLoadHandler_bInitialized do Wait(CustomEvent("OnStep")) end -- create a savegame callback worldGlobals.AddSaveGameCallback("PrintSaved", function() print("Saved") end) -- create a savegame load callback worldGlobals.AddLoadGameCallback("PrintLoaded", function() print("Loaded") end)

WARNING: You cannot use Wait() functions in these callbacks, and you cannot use any other ways to suspend your function thread. Doing so will break the code, as these coroutines suspending is not supported at C++ side.

Q: Why should I use this mod, instead of handling OnSaveGame and OnLoadGame calls on my own?
A: While you indeed can handle these functions yourself, this will make your mod incompatible with any other mod which also handles these calls. This mod creates a standardized usage, allowing the mods to be compatible with each other.

Q: Why this mod is not present in Siberian Mayhem workshop?
A: Many Siberian Mayhem features rely on heavy scripting, which includes dealing with savegame issues. This is why we included this mod into official Siberian Mayhem release. You can use it as is, with the same syntax, just without a need to subscribe to anything.

If you found any issues, feel free to report here in comments or to me directly in Discord (Asdolg#7797).