@@ -44,6 +44,7 @@ function entityKey(ent)
44
44
end
45
45
return false
46
46
end
47
+
47
48
-- /c game.player.print(serpent.dump(game.player.surface.find_logistic_network_by_position(game.player.position, game.player.force.name).find_cell_closest_to(game.player.position)))
48
49
function hasPocketBots (player )
49
50
local logisticCell = player .character .logistic_cell
@@ -235,30 +236,10 @@ local function initGlob()
235
236
global .version = " 0.0.7"
236
237
end
237
238
238
- if global .version < " 0.0.8" then
239
- local toDelete = {}
240
- for k , e in pairs (global .entitiesToInsert ) do
241
- if e .entity .valid then
242
- for _ , g in pairs (e .entity .surface .find_entities_filtered {area = expandPos (e .position ), type = " entity-ghost" }) do
243
- if g .ghost_name == " module-inserter-proxy" then
244
- e .ghost = g
245
- end
246
- end
247
- if not e .ghost then
248
- table.insert (toDelete , k )
249
- end
250
- else
251
- table.insert (toDelete , k )
252
- end
253
- end
254
- for _ , key in pairs (toDelete ) do
255
- global .entitiesToInsert [key ] = nil
256
- end
257
- global .version = " 0.0.8"
258
- end
259
239
if global .version < " 0.0.9" then
260
240
global .entitiesToInsert = {}
261
241
global .removeTicks = {}
242
+ global .guiVersion = {}
262
243
global .version = " 0.0.9"
263
244
end
264
245
global .version = " 0.0.9"
@@ -277,15 +258,21 @@ end
277
258
function update_gui (player )
278
259
local status , err = pcall (function ()
279
260
if player then
280
- if global .guiVersion [player .name ] and global .guiVersion [player .name ] < " 0.0.7" and player .gui .top [" module-inserter-config-button" ] then
261
+ if not global .guiVersion [player .name ] then
262
+ global .guiVersion [player .name ] = " 0.0.0"
263
+ end
264
+ if global .guiVersion [player .name ] < " 0.0.7" and player .gui .top [" module-inserter-config-button" ] then
281
265
player .gui .top [" module-inserter-config-button" ].destroy ()
282
266
global .guiVersion [player .name ] = " 0.0.7"
283
267
end
284
268
gui_init (player )
285
269
else
286
270
for i ,player in pairs (game .players ) do
287
271
if player .valid and player .connected then
288
- if global .guiVersion [player .name ] and global .guiVersion [player .name ] < " 0.0.7" and player .gui .top [" module-inserter-config-button" ] then
272
+ if not global .guiVersion [player .name ] then
273
+ global .guiVersion [player .name ] = " 0.0.0"
274
+ end
275
+ if global .guiVersion [player .name ] < " 0.0.7" and player .gui .top [" module-inserter-config-button" ] then
289
276
player .gui .top [" module-inserter-config-button" ].destroy ()
290
277
global .guiVersion [player .name ] = " 0.0.7"
291
278
end
@@ -324,13 +311,18 @@ game.on_load(onload)
324
311
325
312
function on_tick (event )
326
313
if global .removeTicks [event .tick ] then
327
- for _ , g in pairs (global .removeTicks [event .tick ]) do
328
- if not g .g .valid and g .p .get_item_count (" module-inserter-proxy" ) > 0 then
329
- g .p .remove_item {name = " module-inserter-proxy" , count = 1 }
330
- global .entitiesToInsert [g .key ] = nil
314
+ local status , err = pcall (function ()
315
+ for _ , g in pairs (global .removeTicks [event .tick ]) do
316
+ if not g .g .valid and g .p .get_item_count (" module-inserter-proxy" ) > 0 then
317
+ g .p .remove_item {name = " module-inserter-proxy" , count = 1 }
318
+ global .entitiesToInsert [g .key ] = nil
319
+ end
331
320
end
321
+ global .removeTicks [event .tick ] = nil
322
+ end )
323
+ if not status then
324
+ debugDump (err , true )
332
325
end
333
- global .removeTicks [event .tick ] = nil
334
326
end
335
327
end
336
328
@@ -382,7 +374,8 @@ game.on_event(defines.events.on_robot_built_entity, function(event)
382
374
end
383
375
end
384
376
end
385
- global .entitiesToInsert [entityKey (entity )] = nil
377
+ local key = entityKey (entity )
378
+ global .entitiesToInsert [key ] = nil
386
379
end
387
380
entity .destroy ()
388
381
end
0 commit comments