-
Notifications
You must be signed in to change notification settings - Fork 0
/
on_tick.lua
36 lines (33 loc) · 956 Bytes
/
on_tick.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function register(state)
if not global.WB_states then
global.WB_states = {state}
else
table.insert(global.WB_states, state)
end
if #global.WB_states == 1 then
script.on_event(defines.events.on_tick, on_tick)
end
end
function on_tick(event)
if #global.WB_states == 0 then
script.on_event(defines.events.on_tick, nil)
else
-- Manually loop because we're removing items.
local i = 1
while i <= #global.WB_states do
local state = global.WB_states[i]
if state.stage <= #state.stages then
tick(state)
i = i + 1
else
table.remove(global.WB_states, i)
end
end
end
end
function on_load()
if global.WB_states and #global.WB_states > 0 then
script.on_event(defines.events.on_tick, on_tick)
end
end
script.on_load(on_load)