Sorry, we don't support your browser.  Install a modern browser

Global.script_state is inconsistent with obj.script_state#1146

For normal objects,

  • The value returned by onSave is assigned to self.script_state.

  • The value of self.script_state persists across save+load.

  • The value of self.script_state is assigned to the JSON field LuaScriptState if the object has no onSave.

None of those things are true for Global.

  • The value returned by Global’s onSave isn’t assigned to Global.script_state.

  • Global.script_state is always an empty string on load (even if it wasn’t empty when the mod was saved).

  • An empty string is assigned to the JSON field LuaScriptState if Global has no onSave, even if a value is assigned to Global.script_state.

Workaround if Global has no onSave:

function onLoad(script_state)
   self.script_state = script_state
   -- Rest of onLoad here...
end

function onSave()
   return self.script_state
end

Workaround if Global has an onSave:

function onLoad(script_state)
   self.script_state = script_state
   -- Rest of onLoad here...
end

function onSave()
   self.script_state = 'value to return'
   return self.script_state
end
5 years ago

Ticket filed, in part, at the request of Benjamin Dobell.

5 years ago