problems with "surface.find_entities_filtered"

Place to get help with not working mods / modding interface.
Post Reply
McGuten
Filter Inserter
Filter Inserter
Posts: 310
Joined: Tue Jun 24, 2014 3:06 pm
Contact:

problems with "surface.find_entities_filtered"

Post by McGuten »

Hey guys i have a little problem with surface.find_entities_filtered.

I have that code:

Code: Select all

local foundProxies = surface.find_entities_filtered{area = {{wagon.position.x - 3, wagon.position.y - 3}, {wagon.position.x + 3, wagon.position.y + 3}}, name = "proxyType"}
And it give me a text error: attempt to index local 'surface' (a nil value)
That is in the line 549 from control.lua, but in lines 289, 312, 336, 531 and 549
Someone know how to fix it?

Thanks you all ^^
Attachments
control.lua
control.lua for problem
(39.19 KiB) Downloaded 114 times
Image

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

Re: problems with "surface.find_entities_filtered"

Post by orzelek »

Short answer - adding parameter to function without sending it there makes it a nil.

Long answer - you need to figure out whats the surface not just add it as parameter :D
If wagon is an entity it has it's surface accessible from surface member - try using wagon.surface instead of adding parameter to the function.

McGuten
Filter Inserter
Filter Inserter
Posts: 310
Joined: Tue Jun 24, 2014 3:06 pm
Contact:

Re: problems with "surface.find_entities_filtered"

Post by McGuten »

wow, it work fine

but only in lane 549, lane 289 its for create a rail powered, and it isnt work with that...

Code: Select all

	local staticProxyOwners = surface.find_entities_filtered{area = {{position.x - 0.5, position.y - 0.5}, {position.x + 0.5, position.y + 0.5}}}
Image

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

Re: problems with "surface.find_entities_filtered"

Post by orzelek »

McGuten wrote:wow, it work fine

but only in lane 549, lane 289 its for create a rail powered, and it isnt work with that...

Code: Select all

	local staticProxyOwners = surface.find_entities_filtered{area = {{position.x - 0.5, position.y - 0.5}, {position.x + 0.5, position.y + 0.5}}}
You are calling it on line 37 without giving it any surface so it's nil the function.
Since it's on_tick might be hard to get a hold of surface there.
You can use this one:

Code: Select all

local surface = game.surfaces['nauvis']
This line will give you base planetary surface. No idea what will happen when we move to 0.13 and up but works for now.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: problems with "surface.find_entities_filtered"

Post by ratchetfreak »

or loop over all surfaces

however if you got that position from an entity then grab the entities surface

McGuten
Filter Inserter
Filter Inserter
Posts: 310
Joined: Tue Jun 24, 2014 3:06 pm
Contact:

Re: problems with "surface.find_entities_filtered"

Post by McGuten »

Well, it work now ^^

now show me other error, about equals... now doesnt exist, what function I should use?

Code: Select all

if wagonData.wagon ~= nil and wagon ~= nil and wagonData.wagon.equals(wagon) then
Image

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: problems with "surface.find_entities_filtered"

Post by ratchetfreak »

McGuten wrote:Well, it work now ^^

now show me other error, about equals... now doesnt exist, what function I should use?

Code: Select all

if wagonData.wagon ~= nil and wagon ~= nil and wagonData.wagon.equals(wagon) then
use ==:

Code: Select all

if wagonData.wagon ~= nil and wagon ~= nil and wagonData.wagon == wagon then

McGuten
Filter Inserter
Filter Inserter
Posts: 310
Joined: Tue Jun 24, 2014 3:06 pm
Contact:

Re: problems with "surface.find_entities_filtered"

Post by McGuten »

Thanks you all ^^
Image

Post Reply

Return to “Modding help”