here's my striped-down control.lua. Down in the for loop I have marked a part in the for loop that only gets executed once even though there are multiple iterations through the loop:
Code: Select all
local enable_debug_print = true
local taggable_types={"tree"}
function debug_print(msg)
if enable_debug_print then game.print(msg) end
end
function is_taggeable_entity(entity)
debug_print(" is_taggeable_entity trace IN")
-- interesting entities have more to mine for than just wood
if not entity.minable then
debug_print(" entity not minable")
return false
end
local mining = entity.prototype.mineable_properties
if mining.results or mining.result then
debug_print(" mining results")
return true
else
debug_print(" no mining result")
return false
end
debug_print(" how did we even get here???")
return false
end
function chunk_charted(event)
debug_print('=================================================')
local surface = game.get_surface(event.surface_index)
local area = event.area
local taggeable_entities = {}
local chunk_entities = surface.find_entities_filtered{area=area, type=taggable_types}
debug_print(tostring(#chunk_entities)..' entities in chunk')
for _, entity in pairs(chunk_entities) do
debug_print(tostring(_)..': test entity '..entity.name)
-- why is this only executed once??
local taggeable = is_taggeable_entity(entity)
if taggeable then
debug_print(' found taggeable entity.name: '..entity.name)
table.insert(taggeable_entities, entity)
else
debug_print(" not taggeable")
end
-- until here?
debug_print( 'entity tested '..entity.name)
end
--
end
script.on_event(defines.events.on_chunk_charted, chunk_charted)