Add non-active counter & flip-flop components

This commit is contained in:
2022-06-30 15:17:54 +01:00
parent b7f74ccb1a
commit 96b4176f8b
8 changed files with 121 additions and 30 deletions

View File

@@ -1,11 +1,3 @@
local allItems = {}
Hook.Add("item.created", "countercomponent.init", function(item)
if item.Prefab.Identifier == "countercomponent" then
allItems[item] = true
end
end)
local signalReceived = function(signal, connection)
local this = connection.Item
local mem = this.Components[2]
@@ -24,13 +16,8 @@ local signalReceived = function(signal, connection)
elseif input < 0 then
mem.value = tostring(-input)
end
this.SendSignal(mem.value, "state_out")
end
local think = function()
for component, _ in pairs(allItems) do
component.SendSignal(component.Components[2].value, "state_out")
end
end
Hook.Add("think", "countercomponent.think", think)
Hook.Add("signalreceived.countercomponent", "countercomponent.signalReceived", signalReceived)