Global.script_state is not reset to "" on load. This means the script_state from one mod can leak into another mod.
This issue can very easily be demonstrated using the following:
Code:
function onLoad()
print("Global onLoad " .. logString(self.script_state))
if self.script_state == "" then
self.script_state = 1
else
self.script_state = tonumber(self.script_state) + 1
end
end
function onSave()
return self.script_state
end
Save this to a file, then load the module.
Code:
Test Module loading...
Loading complete.
Global onLoad
Then load it again
Code:
Test Module loading...
Loading complete.
Global onLoad 1
Then load it again
Code:
Test Module loading...
Loading complete.
Global onLoad 2
To be clear, saving is not necessary.
Thankfully, this just affects Global, not other objects.
As a workaround, I strongly recommend that all developers add the following to Global.onLoad to avoid issues from having another mod's state loaded into your own.
Code:
-- Loading a module doesn't clear this!!!
-- https://forums.tabletopsimulator.com/showthread.php?9344-BUG-SCRIPT-Global-script_state-survives-load&p=29892
-- We'll clear it ourselves to avoid having other modules corrupt ours.
Global.script_state = ""