英雄萨姆4

英雄萨姆4

评价数不足
Save & Load Script Functions Handler
   
奖励
收藏
已收藏
取消收藏
Type: Additions
文件大小
发表于
更新日期
83.276 KB
2021 年 9 月 21 日 上午 8:42
2021 年 9 月 21 日 上午 10:59
3 项改动说明 ( 查看 )

订阅以下载
Save & Load Script Functions Handler

描述
[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).