#is there a default method for getting an

1 messages · Page 1 of 1 (latest)

wise briar
#

object.getData()["ColorDiffuse"]

fierce latch
#

thanks!

wise briar
#

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
ruby hinge
#

Also there is no need for the loop through the data table. lua if data.ColorDiffuse ~= nil then ...

wise briar
ruby hinge
#

It is indeed an object, though it hasn't always been fully formed.