Tabletop Simulator

Tabletop Simulator

View Stats:
Can you create a scripting zone from within a script?
I would like to create over a hundred scripting zones at regular intervals. I don't want to use the zone creation tool to tediously place the zones, get the GUID and enter these into my script. Rather, I would rather have my script run a for-loop and create the zones and store them in a table.

Is it possible to create zones from within a script?
< >
Showing 1-6 of 6 comments
jolly Aug 9, 2020 @ 10:54am 
You can spawn in scripting zones with the spawn object function

https://api.tabletopsimulator.com/base/#spawnobject

the type is "ScriptingTrigger"

https://api.tabletopsimulator.com/built-in-object/
alto_saxophone Aug 9, 2020 @ 1:43pm 
I can create the zone, but when I call getObjects(), it doesn't find any (even though I put one in). I also tried to print .guid on the zone, but I get only blank. It doesn't seem to work the same as a zone you create using the zone tool. What am I missing?
alto_saxophone Aug 9, 2020 @ 3:28pm 
Here is a related question. Let's say in the Global onLoad() function, I call a function to spawn a bunch of scripting zones and store references to each zone in a table. Now suppose the players save the game. When they later load the game, will the spawned scripting zones from the previous session be there? Then, when the Global onLoad is called, it will spawn new scripting zones in the same position and store references to each zone in a table... again. Will the scripting zones from the saved game eventually go away with garbage collection? If I keep saving the game and relaunching it, will I end up with hundreds of scripting zones in the same position thus bogging down the system?
latens Aug 11, 2020 @ 9:10am 
Haven't tried it out, but I think the scripting zones will persist through a save and load. To prevent creating multiple zones in the same positions you could just save the table with references. The example on https://api.tabletopsimulator.com/event/#onload pretty much describes how you'd go about saving the table.
marcpawl Jan 25, 2021 @ 12:16am 
Did you get it to work? Can you post demo code?
Last edited by marcpawl; Jan 25, 2021 @ 4:53am
latens Feb 1, 2021 @ 11:46am 
Yeah, I did get it to work. Some demo code below.

positions = { -- a table containing positions to spawn scripting zones [1] = {26.22,1.2,-4.54}, [2] = {26.22,1.2,-1.298}, -- .. etc. } zones = {} -- a table containing a list of zone guids function onSave() local data_to_save = settings saved_data = JSON.encode(data_to_save) return saved_data end function onLoad(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) if(#loaded_data > 0) then zones = loaded_data -- save existing zones else spawnZones() -- spawn zones when no zones exist yet end else spawnZones() -- spawn zones if there is no save data end end function spawnZones() for _,pos in pairs(positions) do spawnObject({ type = 'ScriptingTrigger', -- ScriptingTrigger is a scripting zone position = pos, scale = {1,1,1}, -- or whatever you want callback_function = function(obj) obj.setPosition(pos) zones[#zones + 1] = obj.getGUID() end, sound = false, snap_to_grid = false, }) end end
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Aug 8, 2020 @ 10:57pm
Posts: 6