FlipFlop, Counter, Reactor Controller Components
This commit is contained in:
32
Lua/flipflopcomponent.lua
Normal file
32
Lua/flipflopcomponent.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local allItems = {}
|
||||
|
||||
Hook.Add("item.created", "flipflopcomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "flipflopcomponent" then
|
||||
allItems[item] = true
|
||||
end
|
||||
end)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
local think = function()
|
||||
for component, _ in pairs(allItems) do
|
||||
component.SendSignal(component.Components[2].value, "state_out")
|
||||
end
|
||||
end
|
||||
|
||||
Hook.Add("think", "flipflopcomponent.think", think)
|
||||
Hook.Add("signalreceived.flipflopcomponent", "flipflopcomponent.signalReceived", signalReceived)
|
Reference in New Issue
Block a user