Tutorial Old Creating an Updater Script - LaughingLeader-DOS2-Mods/LeaderLib GitHub Wiki
This guide assumes you know your way around story scripting. If you need help getting started, check out this tutorial: Your First Story Script.
Ideally you should have the following:
- A parent goal to organize all your subgoals.
- An "Updater" goal that is always active. We use this goal to update your registered mod version.
The following database is used by LeaderLib (and associated mods) to store relevant info:
DB_Mods_Registered(_ModID, _AuthorName, _Version)
The goal is for each mod to only ever have one entry.
Our updater script needs the following:
- A procedure to make registering new versions painless.
- A procedure for removing previous versions.
- Registering our mod in the INIT section for first loads with our mod.
- A rule to detect existing versions in previous games, to then force an update.
In the following examples, our sample mod is called "TestMod_GithubExample", and the author name is "CodeBuddy".
To begin, the subroutines we'll use are:
KB:
PROC
TestMod_GithubExample_Updater_RegisterVersion((STRING)_Version)
THEN
TestMod_GithubExample_Updater_RemovePreviousVersions();
DB_Mods_Registered("TestMod_GithubExample", "CodeBuddy", _Version);
PROC
TestMod_GithubExample_Updater_RemovePreviousVersions()
AND
DB_Mods_Registered("TestMod_GithubExample", "CodeBuddy", _Version)
THEN
NOT DB_Mods_Registered("TestMod_GithubExample", "CodeBuddy", _Version);
QRY
TestMod_GithubExample_Updater_UpdateNeeded((STRING)_Version)
AND
NOT DB_Mods_Registered("TestMod_GithubExample", "CodeBuddy", _Version)
THEN
DB_NOOP(1);
If you intend to use this code, remember to replace the "TestMod_GithubExample_"
prefix and mod name / author with values relevant to your mod.
Next, we'll put these procedures into action:
INIT:
TestMod_GithubExample_Updater_RegisterVersion("1.0.0.0");
KB:
IF
GameStarted(_,_)
AND
TestMod_GithubExample_Updater_UpdateNeeded("1.0.0.0")
THEN
TestMod_GithubExample_Updater_RegisterVersion("1.0.0.0");
TestMod_GithubExample_Updater_StartUpdate();
PROC
TestMod_GithubExample_Updater_StartUpdate()
THEN
DebugBreak("[TestMod_GithubExample:Updater] Update detected.");
Using procedures like this allows you to only need to change your version number ("1.0.0.0") in three different places per update, which can be done with a quick "Find and Replace".
Our TestMod_GithubExample_Updater_StartUpdate()
procedure can be used to send an "update" out to other goals, in order to update databases on existing saves with new entries.
The final, complete script can be found here: TestMod_GithubExample_Updater.txt
To take this one step further, you can register both an active goal (so LeaderLib can see if your mod is active), and a mod menu. See: Tutorial: Creaing a LeaderLib Integration Script