Switch
Acts as a wire when active/green, but when black or inactive it acts as a normal object. Must use a polysilicon to switch for trigger events.
It is a craftable and spawnable non-flammable solid.
Here is a list of possible sizes that reach the maximum malleability (144) that have integer components: 1x144x1, 1x72x2, 1x48x3, 1x36x4, 1x24x6, 1x18x8, 1x16x9, 1x12x12, 2x36x2, 2x24x3, 2x18x4, 2x12x6, 2x9x8, 3x16x3, 3x12x4, 3x8x6, 4x9x4, 4x6x6, 8x6x3, 9x8x2, 9x4x4, 12x6x2, 12x4x3
At its default size (2x1x2) it has a durability of 3, at its maximum size it has a durability of 10.
By default, its colour is #111111.
It requires 2 Rubber
and 1 Wire
to be crafted.
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
.