Page 1 of 1

LuaPlayer.can_place_entity wrong number of args

Posted: Thu Feb 01, 2018 4:36 pm
by unobtanium
Hey,

Can someone explain to me how i use LuaPlayer.can_place_entity{name, position, direction}

Whenever i try to call it, it just says "bad argument #-1 to 'can_place_entity' (Wrong number of arguments)"

Code: Select all

player:can_place_entity({"stone-furnace", {x=0, y=0}, defines.direction.north})
player:can_place_entity("stone-furnace", {x=0, y=0}, defines.direction.north)
player:can_place_entity{"stone-furnace", {x=0, y=0}, defines.direction.north}
player:can_place_entity("stone-furnace", {x=0, y=0})
Am i using it wrong? Is this a bug?
Furthermore, does this take player place distance into account? Or just entity hitboxes?

Re: LuaPlayer.can_place_entity wrong number of args

Posted: Thu Feb 01, 2018 4:46 pm
by DaveMcW

Code: Select all

player.can_place_entity{name="stone-furnace", position={x=0, y=0}, direction=defines.direction.north}

Re: LuaPlayer.can_place_entity wrong number of args

Posted: Thu Feb 01, 2018 4:53 pm
by unobtanium
Thanks a lot, that works.
I swear i tested that and it didnt work. My bad!

edit: nevermind, i seem to have used ':' instead of '.'

Re: LuaPlayer.can_place_entity wrong number of args

Posted: Mon Feb 05, 2018 9:50 am
by bobingabout
Keep in mind that pragmatically, there is no difference between a function call of function({}) vs function{}, but they are different than function()

In this particular example:
function({}) and function{} both send a single table. They also typically use a name="name", position={x,y}
function() will send 3 different variables.

Re: LuaPlayer.can_place_entity wrong number of args

Posted: Tue Feb 06, 2018 12:01 am
by Nexela
What bob i saying is..... If the only argument passed to a function is a literal string or literal table, the parenthesis can be omitted

function "string-arg"
function {}

is the same as

function("string-arg")
function({})