Page 1 of 1

[Help] get_nodedef_field

PostPosted: Sat Dec 01, 2012 16:35
by LorenzoVulcan
I implemented get_nodedef_field and it doesn't work.
So i converted it to a more simple and not generical function on what i need:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local function getdrops(nodename)

    if not minetest.registered_nodes[nodename] then

        return nil

    end

    return minetest.registered_nodes[nodename]["drop"]

end


i implemented it with:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            local drop1 = getdrops(nodepos.name)


And:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            if drop1 ~= 'air' then
            inv:add_item("main", drop1)
            end


And it gives me nil value or air value.

Can you help me out?

PostPosted: Sat Dec 01, 2012 16:37
by PilzAdam

PostPosted: Sat Dec 01, 2012 16:38
by LorenzoVulcan

I already tried but it doesn't work with my code.

PostPosted: Sat Dec 01, 2012 16:49
by PilzAdam
LorenzoVulcan wrote:

I already tried but it doesn't work with my code.

You have to loop through the result.

PostPosted: Sat Dec 01, 2012 16:54
by LorenzoVulcan
PilzAdam wrote:
LorenzoVulcan wrote:

I already tried but it doesn't work with my code.

You have to loop through the result.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            local meta = minetest.env:get_meta(pos)
            local inv = meta:get_inventory()
            for _, item1 in ipairs(drop1) do
            if item1 ~= 'air' then  inv:add_item("main", item1) end
            end


It still doesn't add any item in "inv"

PostPosted: Sat Dec 01, 2012 17:10
by PilzAdam
LorenzoVulcan wrote:
PilzAdam wrote:
LorenzoVulcan wrote:I already tried but it doesn't work with my code.

You have to loop through the result.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            local meta = minetest.env:get_meta(pos)
            local inv = meta:get_inventory()
            for _, item1 in ipairs(drop1) do
            if item1 ~= 'air' then  inv:add_item("main", item1) end
            end


It still doesn't add any item in "inv"

Can you give me the code where you declare drop1?

PostPosted: Sat Dec 01, 2012 17:22
by LorenzoVulcan
PilzAdam wrote:Can you give me the code where you declare drop1?

Here it is:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            local drop1 = minetest.get_node_drops(nodepos)

I already tried to insert the tool name.
--------------------------------------------------------
EDIT:I tried this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            local drop1 = minetest.get_node_drops(nodepos.name)


And i tried:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local drop1 = minetest.get_node_drops("default:dirt")


It works if i insert a node name,like "default:dirt".

Here the nodepos declaration:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            nodepos = { x = pos.x, y = pos.y - digs, z = pos.z }

PostPosted: Sat Dec 01, 2012 17:42
by PilzAdam
Ehm...
You know you have to pass the name of the node to get_node_drops() and not the position?

PostPosted: Sat Dec 01, 2012 17:42
by LorenzoVulcan
Just fixed,Thanks a lot!
i just redeclared "nodepos":

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            nodepos = minetest.env:get_node({ x = pos.x, y = pos.y - digs, z = pos.z })