[Done] Crash on Bio_Industries::on_player_built_tile(ID 45)

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Done] Crash on Bio_Industries::on_player_built_tile(ID 45)

Post by TheSAguy »

Hi,
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
Thanks.
Last edited by TheSAguy on Sat Mar 03, 2018 9:24 pm, edited 1 time in total.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Crash on Bio_Industries::on_player_built_tile(ID 45)

Post by eradicator »

Code: Select all

if event.tiles then Solar_Mat (event, surface) end
It sounds more like you're calling Solar_Mat from an event that doesn't actually have tiles. Because on_player_built_tile should always contain event.tiles. If you can reproduce a situation where on_player_built_tile actually doesn't contain any tiles i'd consider that worth a bug report. After all the error you quoted says "nil", so it's not an empty table or something.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Crash on Bio_Industries::on_player_built_tile(ID 45)

Post by TheSAguy »

Thanks eradicator, I'll give it a shot.
Post Reply

Return to “Modding help”