Page 1 of 1

problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 11:37 am
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 ^^

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 11:46 am
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.

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 11:58 am
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}}}

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 12:14 pm
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.

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 12:23 pm
by ratchetfreak
or loop over all surfaces

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

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 12:34 pm
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

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 12:38 pm
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

Re: problems with "surface.find_entities_filtered"

Posted: Sat Jul 18, 2015 12:47 pm
by McGuten
Thanks you all ^^