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

Place to get help with not working mods / modding interface.
Post Reply
yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

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

Post 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

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post by Klonan »

What kind of units are you looking for?
Can you provide a screenshot of the test setup?

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

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

Post 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.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

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

Post by PFQNiet »

Characters aren't units. They're, well, `character`s.

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

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

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

Post 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.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

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

Post 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.

Post Reply

Return to “Modding help”