Spotlight
Emits light in a cone when powered with electricity. Color emition can be changed by coloring it.
It is a craftable and spawnable non-flammable solid.
Here is a list of possible sizes that reach the maximum malleability (256) that have integer components: 1x256x1, 1x128x2, 1x64x4, 1x32x8, 1x16x16, 2x64x2, 2x32x4, 2x16x8, 4x16x4, 4x8x8, 16x8x2, 16x4x4
At its default size (2x2x2) it has a durability of 1, at its maximum size it has a durability of 4.
By default, its colour is #ffffff.
It requires 1 Glass
, 1 Iron
, 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