Page 1 of 1

game.findentitiesfiltered

Posted: Sun Jun 30, 2013 3:20 pm
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:

Re: game.findentitiesfiltered

Posted: Sun Jun 30, 2013 3:39 pm
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 ..."