Results 1 to 1 of 1

Thread: [BUG][SCRIPT] Global.script_state survives load

  1. #1

    [BUG][SCRIPT] Global.script_state survives load

    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 = ""
    Last edited by Kinithin; 01-12-2021 at 01:34 AM.

Similar Threads

  1. Replies: 2
    Last Post: 10-03-2019, 06:17 PM
  2. Replies: 4
    Last Post: 07-14-2019, 07:07 PM
  3. Maximum amount of lines in Global script ?
    By Elemental in forum Scripting
    Replies: 2
    Last Post: 09-13-2016, 07:31 AM
  4. Replies: 6
    Last Post: 08-17-2016, 12:28 PM
  5. Calling functions from the Global Script
    By Tanners in forum Scripting
    Replies: 4
    Last Post: 03-22-2016, 06:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •