I got this crash report with my mod and LandMover mod:
Crash report:
Error while running event
Bio_Industries::on_player_built_tile(ID 45)
Bio_Industries/control.lua:385:bad
argument#1 to 'ipairs'(table expected, got nil)
Lovely Santa said a simple fix would be to check if there actual are tiles in event.tiles.
From Lovely Santa:
"A simple fix would be to check if there actualy are tiles in event.tiles. The issue (I think) is that ipairs(event.tiles) give some issue while trying to iterate over water tiles... But this is weird becose #event.tiles returns the amount of tiles perfectly on my on_player_built_tile event..."
Can someone please tell me how to implement that in my code below:
Code: Select all
local function Solar_Mat (event, surface)
for i, vv in ipairs(event.tiles) do
local position = vv.position
local currentTilename = surface.get_tile(position.x,position.y).name
if currentTilename == "bi-solar-mat" then
writeDebug("Solar Mat has been built")
local force = event.force
local solar_mat = surface.get_tile(position.x,position.y)
local sm_pole_name = "bi_solar_pole"
local sm_panel_name = "bi_solar-panel_for_Solar-Mat"
local create_sm_pole = surface.create_entity({name = sm_pole_name, position = {position.x + 0.5, position.y + 0.5}, force = force})
local create_sm_panel = surface.create_entity({name = sm_panel_name, position = {position.x + 0.5, position.y + 0.5}, force = force})
create_sm_pole.minable = false
create_sm_pole.destructible = false
create_sm_panel.minable = false
create_sm_panel.destructible = false
else
local radius = 0.5
local area = {{position.x - radius, position.y - radius}, {position.x + radius, position.y + radius}}
writeDebug("NOT Solar Mat")
local entities = surface.find_entities(area)
local entity1 = entities[1]
entity1 = surface.find_entities_filtered{area=area, name="bi_solar_pole", limit=1}
if entity1 then
for _, o in pairs(surface.find_entities_filtered({area = area, name = "bi_solar_pole"})) do o.destroy() end
writeDebug("bi_solar_pole Removed")
else
writeDebug("bi_solar_pole not found")
end
--- Remove the Hidden Solar Panel
local entity2 = entities[1]
entity2 = surface.find_entities_filtered{area=area, name="bi_solar-panel_for_Solar-Mat", limit=1}
if entity2 then
for _, o in pairs(surface.find_entities_filtered({area = area, name = "bi_solar-panel_for_Solar-Mat"})) do o.destroy() end
writeDebug("bi_solar-panel_for_Solar-Mat Removed")
else
writeDebug("bi_solar-panel_for_Solar-Mat not found")
end
end
end
end
local function Player_Tile_Built(event)
local player = game.players[event.player_index]
local surface = player and player.surface
Solar_Mat (event, surface)
end