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

setLuaScript() doesn't work on Global (but advertised as working in API documentation)#3043

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.

2 months ago

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.

2 months ago
1

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

2 months ago
1

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.

2 months ago
1

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!

2 months ago
Changed the status to
Research
2 months ago

this is a bug, yes
Global.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

2 months ago

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.

https://tabletopsimulator.nolt.io/1146

2 months ago