BrickColor: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Anaminus
(fixed)
>JulienDethurens
No edit summary
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{CatUp|Data Types}}
{{Map|Scripting|Data Types}}
{{CatUp|Scripting}}


==BrickColor==
A BrickColor value is a specific color value. They are used instead of [[Color3]] values on bricks and other 3D objects. Each BrickColor has a numeric id, that represents the color. For example, 1 is white, and 45 is a light blue. There are many different colors available: [[BrickColor Codes|see the list here]].


A BrickColor value is a specific color value. They are used instead of [[Color3]] values on bricks and other 3D objects.
==Using BrickColor codes==
 
{{LeftNoticeStart}}
BrickColor values are numbers that represent colors. For example, 1 is white. 45 is a light blue.
 
There are many different colors available, [[BrickColor Codes|see the list here.]]
|}
 
==Using BrickColors==


There are actually two ways to use BrickColor codes, the number code and the color code.
There are actually two ways to use BrickColor codes, the number code and the color code.


Each code has a number associated with it. For example, "White" is 1. You can use either the name of the color, or the number for the color when using the code.
Each code has an id number associated with it. For example, "White" has an id of 1. You can use either the name of the color, or the id number of the color when using the code.


===Using Numbers===
===Using Numbers===


Open up a new place with a part. [[Basic Test Map|Click here for a quick guide on how to set up a script testing Place.]]
Open up a new place with a part. [[Basic Test Map|Click here for a quick guide on how to set up a script testing Place]].


In the Command Line, type in this bit here and hit enter:
In the Command Line, type in this bit here and hit enter:
{{CodeExample}}game.Workspace.Part.BrickColor = BrickColor.new(1)</pre>
game.Workspace.Part.BrickColor = BrickColor.new(1)


The brick will turn a bright shade of white. What you just did was tell Lua to change the Part's Brick Color to 1, or White. You set Part.BrickColor to a new color by using the BrickColor.new ''constructor.'' You ''constructed'' a new Brickcolor using the color code for White: 1.
The brick will turn a bright white. What you just did was tell Lua to change the Part's BrickColor to 1, or White. You set Part.BrickColor to a new color by using the BrickColor.new [[constructor]]. You ''constructed'' a new Brickcolor from the color code for White, 1.


{|style="text-align:center; -webkit-border-radius: 4px; -moz-border-radius: 4px; height: 100%; background-color: #ffdddd; border-top: solid 2px #ff0000; border-left: solid 2px #ff0000; border-bottom: solid 2px #aa0000; border-right: solid 2px #aa0000; margin: 6px; margin-right: 10px; margin-left: 10px; clear: none; padding: 2px;"
{|style="text-align:center; -webkit-border-radius: 4px; -moz-border-radius: 4px; height: 100%; background-color: #ffdddd; border-top: solid 2px #ff0000; border-left: solid 2px #ff0000; border-bottom: solid 2px #aa0000; border-right: solid 2px #aa0000; margin: 6px; margin-right: 10px; margin-left: 10px; clear: none; padding: 2px;"
Line 41: Line 32:


In the Command Line, type in this bit here and hit enter:
In the Command Line, type in this bit here and hit enter:
{{CodeExample}}game.Workspace.Part.BrickColor = BrickColor.new("White")
game.Workspace.Part.BrickColor = BrickColor.new("White")
</pre>


Instead of telling Lua that you want the brick to be the value of White, or 1, you tell it specifically that you want the brick to be "White". In this case, you used a [[String]] instead of a [[Number]].
Instead of telling Lua that you want the brick to be the value of White, or 1, you tell it specifically that you want the brick to be "White". In this case, you used a [[String]] instead of a [[Number]].
For a subset of common colors, an alternate notation can be used:
game.Workspace.Part.BrickColor = BrickColor.White()


===Using Color3 Values===
===Using Color3 Values===


[[Color3]]s work similar to [[Vector3]]s, in that they both use 3 numbers.
[[Color3]]s contain 3 numbers, representing the red, green, and blue component of the color.


Just like before, open up a new place with a part. [[Basic Test Map|Click here for a quick guide on how to set up a script testing Place.]]
Just like before, open up a new place with a part. [[Basic Test Map|Click here for a quick guide on how to set up a script testing Place.]]


In the Command Line, type in this bit here and hit enter:
In the Command Line, type in this bit here and hit enter:
{{CodeExample}}game.Workspace.Part.BrickColor = BrickColor.new(Color3.new(1, 1, 1))
game.Workspace.Part.BrickColor = BrickColor.new(Color3.new(1, 1, 1))
</pre>


This sets the R G B settings for the Color3 to full, full, full. Meaning: white! Same thing as the above two examples, just a different way to get there.
This sets the R, G, and B components of the color to full brightness, creating white. Same thing as the above two examples, just a different way to get there.


===Color codes===
===Color codes===
Line 62: Line 54:




==[[Constructors]]==
==Constructors==




{|border="1" cellspacing="5"  style=" -webkit-border-radius: 4px; -moz-border-radius: 4px; height: 100%; background-color: #FFFFFF; border-top: dashed 2px #ff0000; border-left: dashed 2px #ff0000; border-bottom: dashed 2px #aa0000; border-right: dashed 2px #aa0000; margin: 6px; margin-right: 10px; margin-left: 10px; clear: none; padding: 2px;"
{| class="wikitable"
! Function                    !!  Description
! Function                    !!  Description
|-
|-
Line 76: Line 68:
|  BrickColor.Random()        ||  Returns a random BrickColor  
|  BrickColor.Random()        ||  Returns a random BrickColor  
|-
|-
|  BrickColor.White()        ||  Returns White
|  BrickColor.White()        ||  Returns White (1)
|-
|-
|  BrickColor.Gray()          ||  Returns Gray
|  BrickColor.Gray()          ||  Returns Medium stone grey (194)
|-
|-
|  BrickColor.DarkGray()      ||  Returns Dark Gray
|  BrickColor.DarkGray()      ||  Returns Dark stone grey (199)
|-
|-
|  BrickColor.Black()        ||  Returns Black
|  BrickColor.Black()        ||  Returns Black (26)
|-
|-
|  BrickColor.Red()          ||  Returns Red
|  BrickColor.Red()          ||  Returns Bright red (21)
|-
|-
|  BrickColor.Yellow()        ||  Returns Yellow
|  BrickColor.Yellow()        ||  Returns Bright yellow (24)
|-
|-
|  BrickColor.Green()        ||  Returns Green
|  BrickColor.Green()        ||  Returns Dark green (28)
|-
|-
|  BrickColor.Blue()          ||  Returns Blue
|  BrickColor.Blue()          ||  Returns Bright blue (23)
|-
|-
|}
|}


These properties are read only (meaning you can't set BrickColor.r = 5) but you can use them for other things.
These properties are read-only (meaning you can't set BrickColor.r = 5) but you can use them for other things.


{|border="1" cellspacing="5"  style=" -webkit-border-radius: 4px; -moz-border-radius: 4px; height: 100%; background-color: #FFFFFF; border-top: dashed 2px #ff0000; border-left: dashed 2px #ff0000; border-bottom: dashed 2px #aa0000; border-right: dashed 2px #aa0000; margin: 6px; margin-right: 10px; margin-left: 10px; clear: none; padding: 2px;"
{| class="wikitable"
! Property          !! Type      !! Description
! Property          !! Type      !! Description
|-
|-
Line 111: Line 103:
|  BrickColor.b      || [[Number]] || the blue component (between 0 and 1)
|  BrickColor.b      || [[Number]] || the blue component (between 0 and 1)
|}
|}
[[Category:Data Types]]
[[Category:Data types]]

Latest revision as of 13:47, 7 April 2012

A BrickColor value is a specific color value. They are used instead of Color3 values on bricks and other 3D objects. Each BrickColor has a numeric id, that represents the color. For example, 1 is white, and 45 is a light blue. There are many different colors available: see the list here.

Using BrickColor codes

There are actually two ways to use BrickColor codes, the number code and the color code.

Each code has an id number associated with it. For example, "White" has an id of 1. You can use either the name of the color, or the id number of the color when using the code.

Using Numbers

Open up a new place with a part. Click here for a quick guide on how to set up a script testing Place.

In the Command Line, type in this bit here and hit enter:

game.Workspace.Part.BrickColor = BrickColor.new(1)

The brick will turn a bright white. What you just did was tell Lua to change the Part's BrickColor to 1, or White. You set Part.BrickColor to a new color by using the BrickColor.new constructor. You constructed a new Brickcolor from the color code for White, 1.

Property you're changing Set To Value you want to set it to
game.Workspace.Part.BrickColor = BrickColor.new(1)
The color of "Part" Set to This value

Using Names

Just like before, open up a new place with a part. Click here for a quick guide on how to set up a script testing Place.

In the Command Line, type in this bit here and hit enter:

game.Workspace.Part.BrickColor = BrickColor.new("White")

Instead of telling Lua that you want the brick to be the value of White, or 1, you tell it specifically that you want the brick to be "White". In this case, you used a String instead of a Number.

For a subset of common colors, an alternate notation can be used:

game.Workspace.Part.BrickColor = BrickColor.White()

Using Color3 Values

Color3s contain 3 numbers, representing the red, green, and blue component of the color.

Just like before, open up a new place with a part. Click here for a quick guide on how to set up a script testing Place.

In the Command Line, type in this bit here and hit enter:

game.Workspace.Part.BrickColor = BrickColor.new(Color3.new(1, 1, 1))

This sets the R, G, and B components of the color to full brightness, creating white. Same thing as the above two examples, just a different way to get there.

Color codes

There are actually a great many color codes, not just the 64 colors available in the Color Picker window. The list is available here.


Constructors

Function Description
BrickColor.new(val) Returns a BrickColor (from val of a Number, String, Color3)
BrickColor.new(r, g, b) Returns a BrickColor from Color3 of r,g,b
BrickColor.palette(val) Returns a BrickColor (from val of a Number (0-63))
BrickColor.Random() Returns a random BrickColor
BrickColor.White() Returns White (1)
BrickColor.Gray() Returns Medium stone grey (194)
BrickColor.DarkGray() Returns Dark stone grey (199)
BrickColor.Black() Returns Black (26)
BrickColor.Red() Returns Bright red (21)
BrickColor.Yellow() Returns Bright yellow (24)
BrickColor.Green() Returns Dark green (28)
BrickColor.Blue() Returns Bright blue (23)

These properties are read-only (meaning you can't set BrickColor.r = 5) but you can use them for other things.

Property Type Description
BrickColor.Number Number The unique number that identifies the BrickColor
BrickColor.Name String the name associated with the BrickColor
BrickColor.Color Color3 the Color3 associated with the BrickColor
BrickColor.r Number the red component (between 0 and 1)
BrickColor.g Number the green component (between 0 and 1)
BrickColor.b Number the blue component (between 0 and 1)