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: 28
Joined: Fri Nov 04, 2016 11:58 am
Contact:

LuaPlayer.can_place_entity wrong number of args

Post by unobtanium » Thu Feb 01, 2018 4:36 pm

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: 2757
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

Post by DaveMcW » Thu Feb 01, 2018 4:46 pm

Code: Select all

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

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

Re: LuaPlayer.can_place_entity wrong number of args

Post by unobtanium » Thu Feb 01, 2018 4:53 pm

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: 6661
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: LuaPlayer.can_place_entity wrong number of args

Post by bobingabout » Mon Feb 05, 2018 9:50 am

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.

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

Re: LuaPlayer.can_place_entity wrong number of args

Post by Nexela » Tue Feb 06, 2018 12:01 am

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”

Who is online

Users browsing this forum: No registered users