game.findentitiesfiltered

Place to get help with not working mods / modding interface.
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

game.findentitiesfiltered

Post by ficolas »

Code: Select all

		if glob.alloyinserter~=nil then
			for i,e in pairs(glob.alloyinserter) do
				if e.entity.isvalid() then
					foundryes=game.findentitiesfiltered({area = {{e.entity.position.x+2, e.entity.position.y+2}, {e.entity.position.x-2, e.entity.position.y-2}}, name="foundry"})
					if foundryes[1]~=nil then
						game.getplayer().print("There are more than one foundries near an alloy inserter, it wont work")
					elseif foundryes[0]~=nil then
						for index,data in pairs(glob.foundry) do
							if data.entity.position.x==foundryes[0].position.x and data.entity.position.y==foundryes[0].position.y then
								for ind,dat in pairs(e.data) do
									game.getplayer().print(ind.." "..dat)
								end
								for ind,dat in pairs(glob.foundry.metals) do
									game.getplayer().print(ind.." "..dat)
								end
								if tequals(e.data, glob.foundry.metals) then
									e.entity.setactive(false)
								end
								break
							end
						end
					else
						game.getplayer().print("No foundryes have been found")
					end
				else
					table.remove(glob.alloyinserter,i)
				end
			end
		end
game.findentitiesfiltered never finds entities, I dont know if I did something wrong, please help D:

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: game.findentitiesfiltered

Post by drs9999 »

Here is one problem:

Code: Select all

foundryes=game.findentitiesfiltered({area = {{e.entity.position.x+2, e.entity.position.y+2}, {e.entity.position.x-2, e.entity.position.y-2}}, name="foundry"})
You have to change it in

Code: Select all

foundryes=game.findentitiesfiltered({area = {{e.entity.position.x-2, e.entity.position.y-2},{e.entity.position.x+2, e.entity.position.y+2}}, name="foundry"})
Also LUA-table indices starts at 1 not 0
So you have to change the if-statements to "if foundryes[2]~=nil then ... elseif foundryes[1]~=nil then ..."

Post Reply

Return to “Modding help”