Closed Nexela closed 7 years ago
The on_tick
event stays registered for only one tick so, I think the chances of this causing a problem are quite low. I'll fix it though.
Is this what you had in mind?
diff --git a/control.lua b/control.lua
index e9846d9..195a0a1 100644
--- a/control.lua
+++ b/control.lua
@@ -359,6 +359,7 @@ script.on_event(defines.events.on_put_item, function(event)
printf("here we go")
selection.state = item_state.placing
+ global.on_tick_registered = true
script.on_event(defines.events.on_tick, on_tick)
end)
@@ -579,6 +580,7 @@ function on_tick(event)
end
end
script.on_event(defines.events.on_tick, nil)
+ global.on_tick_registered = false
end
@@ -608,3 +610,9 @@ do
end)
end
+
+script.on_load(function()
+ if global.on_tick_registered then
+ script.on_event(defines.events.on_tick, on_tick)
+ end
+end)
That looks good from up here. Thanks!
You are conditionally registering/removing on_tick without keeping track syncing with on_load