Find entities in two adjacent areas without overcounting

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
thesixthroc
Inserter
Inserter
Posts: 24
Joined: Wed Apr 29, 2020 9:53 pm
Contact:

Find entities in two adjacent areas without overcounting

Post by thesixthroc »

If I have areas A and B which are rectangles directly next to each other (but of different sizes), and I want to find the entities that exist in the union of the two regions, I could try calling .find_entities(A) and .find_entities(B) and adding the resulting tables together.

Large objects can straddle the divide, however, and appear in both lists, so they would be double-counted. I don't know how to compare if two entity objects are equal, though, in order to remove duplicates. The following code doesn't work:

Code: Select all

local hash, joint_list_2 = {}
for _, e in pairs(joint_list) do
	if (not hash[e]) then
		hash[e] = true
		joint_list_2[#joint_list_2 + 1] = e
	end
end
because we just get back joint_list again.

Any suggestions?

thesixthroc
Inserter
Inserter
Posts: 24
Joined: Wed Apr 29, 2020 9:53 pm
Contact:

Re: Find entities in two adjacent areas without overcounting

Post by thesixthroc »

Nevermind - trivial problem.

Factorio supports comparing entities with '==' but not with key-value fetching.

Post Reply

Return to “Modding discussion”