Navigation

Saturday, December 3, 2011

Scripting Lesson 1: Changing Brick Colors

      In this lesson I'll explain an easy way to change the color of a brick in game. This gives you the ability to make a button that changes color when pressed, a disco floor, or maybe even a light that changes colors on a car.

In This Lesson:
  • BrickColor.
  • The meaning of "Parent."
  • "Wait" function.
  • "While true do" loop.
The base script is the following:

script.Parent.BrickColor = BrickColor.new("Bright red")

The idea of this script is that the Parent (the brick with the script placed inside) will have its color changed from its original color to "Bright red."

To jazz the script up a bit we'll add a simple function known as the "wait" function.

The wait function can be used to delay the script or to put time between two parts of the script. Let me show you an example of the wait function added to the BrickColor script.

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright red")


In this script the game will wait a half a second and then change the BrickColor.

One more way that you could make the script different is by putting multiple colors:

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright red")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright blue")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright yellow")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright violet")


In order to take the script to another level you can write "while true do" in the beginning of the script. This results in a loop. When the script reaches its end it will jump back to the start and run again. This can be used to create a disco floor, instead of just stopping on the last color.

while true do

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright red")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright blue")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright yellow")

wait(0.5)
script.Parent.BrickColor = BrickColor.new("Bright violet")

wait(0.5) 
script.Parent.BrickColor = BrickColor.new("Bright green")
end

The script will cycle through each color making them appear for 0.5 seconds on the brick. Place a bunch of these tiles together with the colors in different arrangements in order to create a disco floor scheme.

Enjoy exploring Roblox's color wheel and try changing up the scripts to see what you can do with them.
majoko1 
Majoko1           

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Sorry removed last comment to rewrite it!This scripting lesson is AWESOME it explained the script REALLY well so it made sense

    ReplyDelete