correct call of minetest.node_dig() on_dig() and dig_node()

User avatar
addi
Member
 
Posts: 658
Joined: Thu Sep 20, 2012 03:16
Location: Black-Forest, Germany
GitHub: adrido

correct call of minetest.node_dig() on_dig() and dig_node()

by addi » Wed Aug 05, 2015 18:38

minetest documentation seems to be a bit unclear
http://dev.minetest.net/minetest.register_node says:
Code: Select all
on_dig = function(pos, node, digger)

function on_dig takes 3 parameters, none of them seems to be optional.
http://dev.minetest.net/minetest.node_dig says:
Code: Select all
minetest.node_dig(pos, node, digger)
function also takes 3 arguments non are optional
and now http://dev.minetest.net/minetest.dig_node :
Code: Select all
minetest.dig_node(pos)

only takes pos as argument. It seems to call minetest.node_dig but without the 2nd and 3rd argument.

shouldn't be the correct documentation of on_dig and node_dig be:
Code: Select all
function(pos [,node [,digger]]) 

or should minetest.dig_node(pos) be minetest.dig_node(pos, node, digger) ?
Or do I understand something wrong?

How is the correct call of on_dig()?
Witch arguments do I always get to work with?

Thanks in advance.
 

User avatar
rubenwardy
Moderator
 
Posts: 5833
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: correct call of minetest.node_dig() on_dig() and dig_nod

by rubenwardy » Wed Aug 05, 2015 19:15

lua_api.txt wrote:minetest.dig_node(pos)
* Dig node with the same effects that a player would cause
* Returns true if successful, false on failure (e.g. protected location)


This is meant to be called out of the blue, doesn't need to be in a node definition. You can use it the same as minetest.set_node.

lua_api.txt wrote:minetest.node_dig(pos, node, digger)
* Checks if node can be dug, puts item into inventory, removes node
* Calls functions registered by minetest.registered_on_dignodes()


This is meant to be added to a node def, like on_dig = minetest.node_dig.

lua_api.txt wrote:on_dig = func(pos, node, digger)


these variables are the same number as you can see, they match.

minetest.node_dig != minetest.dig_node.

However, it is inconsistent that node isn't passed. Not passing a digger is understandable, as it's done by code.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest