[Help] get_nodedef_field

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

[Help] get_nodedef_field

by LorenzoVulcan » Sat Dec 01, 2012 16:35

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?
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Dec 01, 2012 16:37

 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Sat Dec 01, 2012 16:38


I already tried but it doesn't work with my code.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Dec 01, 2012 16:49

LorenzoVulcan wrote:

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

You have to loop through the result.
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Sat Dec 01, 2012 16:54

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"
Last edited by LorenzoVulcan on Sat Dec 01, 2012 16:55, edited 1 time in total.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Dec 01, 2012 17:10

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?
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Sat Dec 01, 2012 17:22

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 }
Last edited by LorenzoVulcan on Sat Dec 01, 2012 17:26, edited 1 time in total.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Dec 01, 2012 17:42

Ehm...
You know you have to pass the name of the node to get_node_drops() and not the position?
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Sat Dec 01, 2012 17:42

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 })
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 7 guests

cron