
Per the API documentation: “The functions can be used on Objects, but can also be used on the game world using Global” of which setLuaScript() is included:
setLuaScript(script) Input a string as an entity’s Lua script. Generally only used after spawning a new Object.
Global.setLuaScript() won’t update the global script but works for objects.
I simply want to script updating the Global LuaScript in the JSON which I can do manually by editing & saving the JSON while the mod is running then save & reload without issue (not user-friendly)
This is to incorporate a mechanism to update the mod using a WebRequest to Pastebin as I anticipate this code needing updates initiated by the user.

The object needs to be reloaded after its script is changed for the script to take effect. (setLuaScript does this for you.) You can’t reload Global, so this makes no sense.

Instead, execute your new script using o.executeScript. Search the #scripting channel of the official TTS Discord for docs on this function.

but advertised as working in API documentation
Not all functions work on all objects. Take .getObjects, for example. It only works on zones, decks and bags.

I simply want to update the mod’s JSON’s LuaScript entry with the updated code exactly as if I had manually updated this entry using a text editor by copy/paste. I understand this won’t reload the script as I would instruct the user to save & reload the mod for the update to take effect. I’ll play around with Global.executeScript() & I appreciate the help!


this is a bug, yesGlobal.script_code/Global.script_state are loaded from save states, but changes to them currently aren’t reflected back onto the save state during the save process, thus changing them does not actually let you change the code in any meaningful way

but changes to them currently aren’t reflected back onto the save state
That sounds like you’re talking about a bug I filed at the request of Benjamin Dobell.