Light
Emits light when powered with electricity. Can be colored in different ways, changing the light color.
It is a craftable and spawnable non-flammable solid.
Here is a list of possible sizes that reach the maximum malleability (64) that have integer components: 1x64x1, 1x32x2, 1x16x4, 1x8x8, 2x16x2, 2x8x4, 4x4x4, 8x4x2
At its default size (2x2x2) it has a durability of 1, at its maximum size it has a durability of 3.
By default, its colour is #ffffff.
It requires 2 Silicon
and 2 Wire
to be crafted.
Methods
SetColor(color)
Sets the color of the object.
The color parameter is the Color3
of the color you want to set the object to. It is a Color3
.
local sift = require("sift") -- Grab this fancy library for manipulating tables provided by wos.
-- Get all of the types of objects with a `:SetColor` method and merge them into one big table.
local objects = sift.Array.merge(
GetParts("Light"),
GetParts("LightTube"),
GetParts("SpotLight"),
GetParts("EnergyShield")
)
-- We want this to run infinitely, but we want to run it every frame, rather than every game
-- tick, so we won't use the `Microcontroller.Loop` event.
while true do
-- First we want to get the current time, the function `os.clock` gives us a very precise
-- measurement of the current time (if you want to know, it basically uses the internal
-- clock of the computer running the code).
local currentTime = os.clock()
-- We then use the 'modulo' operator, what this does is it gives you the 'remainder'
-- from the division. So if you do something like `5.25 % 1` you get out the `0.25`,
-- or if you do, say, `31 % 2`, since 31 isn't divisble by 2 you get a remainder of `1`.
-- We do this so we just get the fractional aspect of the time (which would be the
-- milliseconds), giving us a number between 0 and 1.
local hue = currentTime % 1
-- We then construct a `Color3` passing in the value we just calculated, which, since
-- we used the modulo operator is always going to be between 0 and 1, the exact range
-- needed for the 'hue' of the `fromHSV`. We just set the 'saturation' and 'brightness'
-- to 1 to keep the colour nice and bright.
-- A helpful feature of the HSV colour space is that a hue of both `0` and `1` are red!
local color = Color3.fromHSV(hue, 1, 1)
-- Now we have our colour, we just want to apply it to all of our objects, so we'll use
-- a simple for loop. The 'index' or 'key' value is named '_' since we don't need it,
-- and naming it '_' is a good way to say it's an unused variable.
for _, object in objects do
-- Simply call the `SetColor` method (since it's a method, we use a `:` when
-- calling the function, rather than a `.`) passing in the `Color3`!
object:SetColor(color)
end
-- Wait a little bit before updating the colour again!
task.wait()
end
Configurables
Brightness
The brightness of the light. It is a number
.
It ranges between 0 and 2.
LightRange
The range of the light. It is a number
.
It ranges between 1 and 60.
Shadows
Whether or not the light will cast shadows. It is a boolean
.
Events
Configured(configurerId)
Fires when the object is configured.
The configurerId parameter is the UserId
of the player who configured the object. It is a number
.