Page 1 of 1

find_non_colliding_position

Posted: Sun Feb 05, 2017 2:35 pm
by darkfrei
Hi all!

Here is some information: http://lua-api.factorio.com/latest/LuaS ... g_position

find_non_colliding_position(name, center, radius, precision) → Position

Why it's impossible to make something like that?

Code: Select all

local position = nil
local name = "crude-oil"
local center = game.player.position
local radius= 10
local precision = 5
local amount = 5000
for i=1,9 do
	position = game.player.surface.find_non_colliding_position(name=name, center=center, radius=radius, precision=precision)
	if position then 
		game.player.surface.create_entity({name=name, amount=amount, position=position})
	end
end
By game.player.surface.find_non_colliding_position is possible to write:

Code: Select all

position = game.player.surface.find_non_colliding_position(name, center, radius, precision)
but not

Code: Select all

position = game.player.surface.find_non_colliding_position(name=name, center=center, radius=radius, precision=precision)
By game.player.surface.create_entity it's possible.

Re: find_non_colliding_position

Posted: Sun Feb 05, 2017 8:44 pm
by Rseding91
Because it doesn't take a table but takes the arguments directly? What's not to understand about that?

Re: find_non_colliding_position

Posted: Sun Feb 05, 2017 9:18 pm
by darkfrei
Rseding91 wrote:Because it doesn't take a table but takes the arguments directly? What's not to understand about that?
Exactly! Why some function needs one table and another needs arguments? What is the different?

Re: find_non_colliding_position

Posted: Sun Feb 05, 2017 9:34 pm
by dandielo
Seems to me that the "table" accepting functions are there because you don't need to fill all the fields, where for a regular function it forces you to call it with all arguments. I might be wrong on this one :P

Re: find_non_colliding_position

Posted: Tue Feb 07, 2017 8:48 pm
by theRustyKnife
dandielo wrote:
Quote
You are actually wrong, Lua allows you to omit arguments. It's effectively the same as passing nil instead.
However, it depends on the implementation of the function to handle that properly.
You can also pass extra arguments - those will just be ignored.

Also I think in this (the last snippet from the first post):

Code: Select all

position = game.player.surface.find_non_colliding_position(name=name, center=center, radius=radius, precision=precision)
There should be curly braces instead of the normal ones.
It won't work either way, but this wouldn't even be valid Lua code.

Cheers TRK