TriggerRelay
Acts as a TriggerWrite
when active/green, but when black or inactive it acts as a normal object, it will not toggle when exposed to Polysilicon
signals, rather, it will pass them through if it is active, as if it were a normal signal.
Configurables
SwitchValue
Determines whether the switch is active or not. It is a boolean
.
local sift = require("sift") -- Grab this fancy library for manipulating tables provided by wos.
-- Get all of the types of objects with a `SwitchValue` (save for `TemperatureGate`) configurable
-- and merge them into one big table.
local objects = sift.Array.merge(
GetParts("Switch"),
GetParts("TriggerSwitch"),
GetParts("Valve"),
GetParts("Hatch"),
GetParts("HeatValve")
)
-- Have a 50/50 chance to be on/off when the code starts running.
local initialState = math.random() > 0.5
-- Iterate over all of the switch objects and disable them. `_` is used as a placeholder variable.
for _, switch in objects do
-- You could alternatively do `switch:Configure({ SwitchValue = initialState })`
switch.SwitchValue = initialState
end
-- Connect to the `Loop` event of the `Microcontroller` that is running the code,
-- this will make the code within run precisely every game tick.
Microcontroller.Loop:Connect(function()
-- Iterate over all the switches again!
for _, switch in objects do
-- Here we *read* the `SwitchValue`, then invert it, then write it back, as
-- to toggle the switch.
switch.SwitchValue = not switch.SwitchValue
end
end)
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
.
OnClick(clickerId)
Fires when the object is clicked.
The clickerId parameter is the UserId
of the player who clicked the object. It is a number
.