Page 1 of 1

[1.1.5] surface.find_units function doesn't work at all.

Posted: Sat Dec 12, 2020 3:35 am
by yagaodirac
self.surface.find_entities{self.pos-{10,10},self.pos+{10,10}} works.
self.surface.find_units {area= {self.pos-{10,10},self.pos+{10,10}},force="player",condition="same"} doesn't.

And some eneity even return a "userdata" when I look into its .force.name

code:
local result = self.surface.find_units {area= {self.pos-{10,10},self.pos+{10,10}},force="player",condition="all"}

log(serpent.block(#result))
for k,v in pairs(result) do
log(k)
log(serpent.block(v))
log(serpent.block(v.name))
log(serpent.block(v.force.name))
end

Re: [1.1.5] surface.find_units function doesn't work at all.

Posted: Sat Dec 12, 2020 9:39 am
by Klonan
What kind of units are you looking for?
Can you provide a screenshot of the test setup?

Re: [1.1.5] surface.find_units function doesn't work at all.

Posted: Sat Dec 12, 2020 11:32 am
by yagaodirac
Klonan wrote:
Sat Dec 12, 2020 9:39 am
What kind of units are you looking for?
Can you provide a screenshot of the test setup?
character. OK, I'll paste as much useful info and code here tomorrow.

Re: [1.1.5] surface.find_units function doesn't work at all.

Posted: Sat Dec 12, 2020 12:18 pm
by PFQNiet
Characters aren't units. They're, well, `character`s.

`find_units` specifically looks for entities of type `unit`, not of type `character`.

Re: [1.1.5] surface.find_units function doesn't work at all.

Posted: Sun Dec 13, 2020 5:09 am
by yagaodirac
PFQNiet wrote:
Sat Dec 12, 2020 12:18 pm
Thanks. I actually guessed this possibility. But I didn't want it to be the answer, since I didn't find any function named find_character.

Re: [1.1.5] surface.find_units function doesn't work at all.

Posted: Sun Dec 13, 2020 12:28 pm
by orzelek
If you want to search only for player you can use the find entity filtered variant:
https://lua-api.factorio.com/latest/Lua ... s_filtered
Players are of type character so it will grab only them easily.