20 lines
565 B
Lua
20 lines
565 B
Lua
local signalReceived = function(signal, connection)
|
|
local this = connection.Item
|
|
local mem = this.Components[2]
|
|
|
|
if signal.value == "" then return end
|
|
local input = tonumber(signal.value) or 1
|
|
|
|
if input == 1 then
|
|
if mem.value == "0" then mem.value = "1" else mem.value = "0" end
|
|
elseif input == 0 then
|
|
mem.value = "0"
|
|
elseif input == -1 then
|
|
mem.value = "1"
|
|
end
|
|
|
|
this.sendSignal(mem.value, "state_out")
|
|
end
|
|
|
|
Hook.Add("signalreceived.flipflopcomponent", "flipflopcomponent.signalReceived", signalReceived)
|