find_non_colliding_position

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

find_non_colliding_position

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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13247
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: find_non_colliding_position

Post by Rseding91 »

Because it doesn't take a table but takes the arguments directly? What's not to understand about that?
If you want to get ahold of me I'm almost always on Discord.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: find_non_colliding_position

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

User avatar
dandielo
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Mar 30, 2016 9:25 pm
Contact:

Re: find_non_colliding_position

Post 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
Resurrecting DyTech's Mods, more about this Here!

User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: find_non_colliding_position

Post 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

Post Reply

Return to “Modding discussion”