BrickColor (Property): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>NXTBoy
spelling mistake
>Legend26
No edit summary
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{CatUp|Properties}}
{{CatUp|Properties}}
[[BrickColor|For an explanation of BrickColor, click here]]
<onlyinclude>{{Property|
name = BrickColor
|property = [[Scripting#BrickColor|BrickColor]] BrickColor
|description = Stores the color of the object
|object = [[RBX.lua.FlagStand (Object)|Flagstand]], [[RBX.lua.Part (Object)|Part]], [[RBX.lua.Seat (Object)|Seat]], [[RBX.lua.SpawnLocation (Object)|SpawnLocation]]
|}}</onlyinclude>
<br style="clear:both" />
==Example==
<pre>
--[[ NOTE:  To compare the property BrickColor with the name of a color,
you need to use tostring() to convert BrickColor to a string.  Even though
print(otherPart.Parent.Torso.BrickColor) does return the name of the color,
you cannot use it by itself in a comparison. ]]--


<onlyinclude>{{Property
|name        = BrickColor
|property    = [[BrickColor]] BrickColor
|description = Stores the color of the object.
|object      = BasePart
}}</onlyinclude>
{{clear floats}}
== Comparison ==
To compare the property BrickColor with the name of a color, you need to index the 'Name' property of the BrickColor. That will convert the BrickColor to a string. Even though this script below does output the name of the color, you cannot compare a color and a string.
{{Example|<pre>
print(otherPart.Parent.Torso.BrickColor)
</pre>}}
== Example ==
{{Example|<pre>
function onTouched(otherPart)
function onTouched(otherPart)
     print(otherPart.Parent.Torso.BrickColor) -- outputs the name of the color  
     print(otherPart.Parent.Torso.BrickColor) -- Outputs the name of the color  
     if otherPart.Parent.Torso.BrickColor == "Bright red" then -- This will not match
     if otherPart.Parent.Torso.BrickColor == "Bright red" then -- This will not match
         print("Never gets executed")
         print("Never gets executed")
     elseif tostring(otherPart.Parent.Torso.BrickColor) == "Bright red" then -- This will match
     elseif otherPart.Parent.Torso.BrickColor.Name == "Bright red" then -- This will match
         print("Match occurred")
         print("Match occurred")
     end
     end
end  
end
</pre>
</pre>}}


== See Also ==
== See Also ==


[[BrickColor Codes]]
[[BrickColor Codes]]
[[Category:Properties]]
[[Category:Properties]]

Latest revision as of 23:15, 1 January 2012

BrickColor
Property BrickColor BrickColor
Description Stores the color of the object.
Member of BasePart


Comparison

To compare the property BrickColor with the name of a color, you need to index the 'Name' property of the BrickColor. That will convert the BrickColor to a string. Even though this script below does output the name of the color, you cannot compare a color and a string.

Example
print(otherPart.Parent.Torso.BrickColor)


Example

Example
function onTouched(otherPart)
    print(otherPart.Parent.Torso.BrickColor) -- Outputs the name of the color 
    if otherPart.Parent.Torso.BrickColor == "Bright red" then -- This will not match
        print("Never gets executed")
    elseif otherPart.Parent.Torso.BrickColor.Name == "Bright red" then -- This will match
        print("Match occurred")
    end
end


See Also

BrickColor Codes