LuaPlayer.can_place_entity wrong number of args

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
unobtanium
Inserter
Inserter
Posts: 31
Joined: Fri Nov 04, 2016 11:58 am
Contact:

LuaPlayer.can_place_entity wrong number of args

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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

Post by DaveMcW »

Code: Select all

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

unobtanium
Inserter
Inserter
Posts: 31
Joined: Fri Nov 04, 2016 11:58 am
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

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

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

Post 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({})

Post Reply

Return to “Modding discussion”