Skip to content

Instantly share code, notes, and snippets.

@jorgen99
Created December 7, 2020 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgen99/fe493f731497af3b527650c67551e5a5 to your computer and use it in GitHub Desktop.
Save jorgen99/fe493f731497af3b527650c67551e5a5 to your computer and use it in GitHub Desktop.
changeColor bug in Tabletop Simulator
--
-- Workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=2311549480
--
setup_button_guid = "d6b9ab"
function onLoad()
button_setup("Randomize Players", setup_button_guid, 'setUp', 7000, 2000, 800)
end
function setUp()
radomizePlayers()
end
function radomizePlayers()
printToAll("Giving each player a random color.")
local otherColors = { "Yellow", "Orange", "Purple", "Pink"}
local playerList = Player.getPlayers()
for i, playerRef in ipairs(playerList) do
playerRef.changeColor(otherColors[i])
end
local availableColors = { "White", "Red", "Blue", "Green"}
for _, playerReference in ipairs(Player.getPlayers()) do
local c = getRandom(availableColors)
printToAll(playerReference.steam_name .. " gets color " .. c)
playerReference.changeColor(c)
end
end
function getRandom(tbl)
local index = math.random(1, #tbl)
return table.remove(tbl, index)
end
function button_setup(label, guid, function_name, width, height, font_size)
local button = getObjectFromGUID(guid)
if button == nil then
print("Button '", label, "' does not exist, skipping it...")
return
end
local button_parameters = {}
button_parameters.click_function = function_name
button_parameters.label = label
button_parameters.function_owner = nil
button_parameters.position = { 0, 0.2, 0 }
button_parameters.rotation = { 0, 180, 0 }
button_parameters.width = width
button_parameters.height = height
button_parameters.font_size = font_size
button.createButton(button_parameters)
return button
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment