How do I get this tool to work?

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

How do I get this tool to work?

by scifiboi » Thu Feb 21, 2013 22:18

I am going to cut the backstory from this post and just show you my code:

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
minetest.register_tool("industry:treetap", {
    description = "Tree Tap",
    inventory_image = "treeTap.png",
    on_use = function(itemstack, pointed_thing)
        local pos = minetest.get_pointed_thing_position(pointed_thing, above)
        local node = minetest.env:get_node(pos)
        local node_name = node.name
--        nodePos = minetest.get_pointed_thing_position(pointed_thing, above)
--        node = minetest.env:get_node(nodePos)
        if (node_name ~= "industry:rubbertreefull") then return end
        local stickyResinPos = nodePos
        stickyResinPos.z = stickyResinPos.z + 1
        minetest.env:add_item(stickyResinPos, "industry:stickyresin")
        minetest.env:add_node(nodePos, "industry:rubbertree")
        end
})


, show you the error:

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
21:24:15: ERROR[main]: ServerError: LuaError: error: ...ome/blake/.minetest/mods/minetest/industry/tools.lua:6: bad argument #1 to 'get_node' (table expected, got nil)


And tell you that this error is thrown when I left click a 'industry:rubbertreefull' node. Please don't reply with a mod that already has it implemented, because I'd like for this mod to be entirely mine. :) I've tried several things to get it to work, but it always ends the same - with the game freezing and an error thrown. If you need further details, just ask. Thanks!
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Thu Feb 21, 2013 22:54

scifiboi wrote:-snip-

, show you the error:

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
21:24:15: ERROR[main]: ServerError: LuaError: error: ...ome/blake/.minetest/mods/minetest/industry/tools.lua:6: bad argument #1 to 'get_node' (table expected, got nil)


-snip-

That means that the position you sent to get_node did not exist (i.e. nil). So it means that 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
minetest.get_pointed_thing_position(pointed_thing, above)


... did not exist either, which means that either pointed_thing or above was nil (or both), or that it just didn't find it.

Hope that clarifies something!
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Fri Feb 22, 2013 22:10

The problem is that your function signature for on_use is incorrect (that link is for a craftitem, but it uses the same handler as a tool and the wiki article for minetest.register_tool hasn't been completed yet). The second argument to "on_use" is actually a reference to the object for the player using the item, not the pointed_thing. So insert a third parameter between the two you have declared (it is the position that matters, not the name) and you should be good.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Fri Feb 22, 2013 22:32

Okay, so I threw a random argument in the center, and it got further in the code than usual. But this time, it stops at 'minetest.env:add_node(pos, "industry:rubbertree")' saying that it expected a string in argument #-2 but got nil. I am almost %100 sure that the second argument is a string! :P
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

User avatar
Topywo
Member
 
Posts: 1718
Joined: Fri May 18, 2012 20:27

by Topywo » Fri Feb 22, 2013 22:37

You could try:
minetest.env:add_node(pos, {name = "industry:rubbertree"})

Edit: typo.
Last edited by Topywo on Fri Feb 22, 2013 22:38, edited 1 time in total.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Fri Feb 22, 2013 22:40

Wow, I can't believe it worked. I made that mistake just a couple of days ago, and it is so simple. Thanks for that. Excuse me while I go bash my face into a wall. :P
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Fri Feb 22, 2013 23:53

Glad you got it working. It's an easy mistake to make seeing as you rarely need to mess with the "param1" and "param2" fields that comprise the rest of a node, so for all intents and purposes it basically IS just a name.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 27 guests

cron