BrickColor (Property): Difference between revisions

From Goodblox Wiki
Jump to navigationJump to search
(Created page with "{{CatUp|Properties}} {{Property| name = BrickColor |property = BrickColor BrickColor |description = Stores the color of the object |object = GBX.lu...")
 
No edit summary
Line 5: Line 5:
|property = [[Scripting#BrickColor|BrickColor]] BrickColor
|property = [[Scripting#BrickColor|BrickColor]] BrickColor
|description = Stores the color of the object
|description = Stores the color of the object
|object = [[GBX.lua.FlagStand (Object)|Flagstand]], [[GBX.lua.Part (Object)|Part]], [[GBX.lua.Seat (Object)|Seat]], [[GBX.lua.SpawnLocation (Object)|SpawnLocation]]
|object = [[GBX.lua.BasePart (Object)|BasePart]]|}}
|}}
|}}


Line 15: Line 15:
you cannot use it by itself in a comparison. ]]--
you cannot use it by itself in a comparison. ]]--


function onTouched(otherPart)
local 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

Revision as of 13:09, 20 September 2021


Property
Name BrickColor
Property BrickColor BrickColor
Description: Stores the color of the object
In Object: BasePart


|}}

Example

 
--[[ 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. ]]--

local 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 tostring(otherPart.Parent.Torso.BrickColor) == "Bright red" then -- This will match
        print("Match occurred")
    end
end 

See Also

Color Reference