#is there a default method for getting an
1 messages · Page 1 of 1 (latest)
Not sure if there's a better way, but I know for sure I've done so with https://api.tabletopsimulator.com/object/#getdata
object.getData()["ColorDiffuse"]
thanks!
To easily compare that value with any of the Color instances, I just set the alpha of that ColorDiffuse value to 1, like this:
-- alpha 1 is needed since equals() evaluates it
function CloneWithAlpha1(color)
local copy = color:copy()
copy:set(copy.r, copy.g, copy.b, 1)
return copy
end
function DoSomethingIfObjectColorToneIsSameAs(playerColor, anObject)
local data = anObject.getData()
for k, v in pairs(data) do
if k == "ColorDiffuse" then
local colorTone = CloneWithAlpha1(v)
if colorTone == Color.fromString(playerColor) then
-- do something upon a match, then probably break or return
end
end
end
end
https://api.tabletopsimulator.com/color/ has functions for this. ```lua
object.getColorTint() -- returns a Color you can use.
Also there is no need for the loop through the data table. lua if data.ColorDiffuse ~= nil then ...
Nice, didn't know that was available.
I think I might have used getData() in the past for getting a Hand Zone's color. Can't recall if a zone is an Object.
It is indeed an object, though it hasn't always been fully formed.