Tabletop Simulator

Tabletop Simulator

Camel Up 2.0 (backwards camels)
Xtal Lattice 28 Oct, 2020 @ 4:27pm
How to make the dice roll automatically when leaving the pyramid
Here is how to make the dice roll automatically when they come out of the pyramid:


Changes to the Global script

Add to onLoad():

-- Holds the dice object that leaves the pyramid so that we can set the flag within the dice. Used for rolling. diceFlagObj = nil


Add to getObjects():

pyramid = getObjectFromGUID('2743e2')


Add to the root of the Global script:

function onObjectLeaveContainer(bag, obj) -- Set the flag for dice leaving the pyramid so that they will roll upon landing on the board. if bag == pyramid then diceFlagObj = obj startLuaCoroutine(Global, "setDiceFlag") end end -- Coroutine used to set the flag for dice leaving the pyramid. Used for rolling when they hit the board, since die positions are preserved in containers. function setDiceFlag() -- When objects leave a container, it takes a moment to spawn before they exist. Pause so they exist when we act on them. for i=1, 5 do coroutine.yield(0) end -- Set the flag in the dice object. diceFlagObj.setVar('rollFlag', 0) -- Necessary for coroutines. return 1 end


Script for each dice object:

-- Dice -- When the die comes out of a bag and hits the table, automatically roll it. function onLoad() -- Flag to indicate whether the dice is ready to roll. Without the flag, the dice will roll endlessly every time it bounces. rollFlag = 2 end function onCollisionEnter(collisionInfo) if rollFlag == 0 then self.roll() rollFlag = 1 end end


I tested this, and it works perfectly on my end.
Last edited by Xtal Lattice; 28 Oct, 2020 @ 4:28pm
< >
Showing 1-2 of 2 comments
wailwhale  [developer] 22 Dec, 2020 @ 11:39am 
Thank you for the update man, I will work on implementing it as soon as I get the chance :)
Xtal Lattice 26 Dec, 2020 @ 6:22pm 
Glad I could help!
< >
Showing 1-2 of 2 comments
Per page: 1530 50