Page 1 of 1

Code not working

Posted: Sun Jun 29, 2014 23:06
by DevBukkitDude
Ok, So this is my a peice of my mod "Timber", This is a run off on the mod that just had a few lines of source, So I started trying to make it deal with leaves, I quit minetest before I finished this, Im back tho.
Anyways, I don't see how this dose not work, maybe cuz this is lua and not luaAPI?
It only failes when I put in the value test if.

Code: Select all

local timber_nodenames={"default:jungletree", "default:papyrus", "default:cactus", "default:tree", "default:leaves", "default:jungleleaves"}
local timber_leaves={"default:leaves", "default:jungleleaves"}

minetest.register_on_dignode(function(pos, oldnode, digger)
    local i=1
    while timber_nodenames[i] ~= nil do
        if oldnode.name == timber_nodenames[i] then
            local npos = { x=pos.x, y=pos.y+1, z=pos.z }
            local nnode = minetest.env:get_node(npos)
            if nnode.name == timber_nodenames[i] then
		if not i == 5 then
                minetest.node_dig(npos, nnode, digger)
		end
            end
        end
        i = i+1
    end
end)

Re: Code not working

Posted: Mon Jun 30, 2014 13:02
by rubenwardy
You haven't understood how the code works.
  • A tree node is dug
  • Minetest triggers the function minetest.register_on_dignode
  • That code checks for a block above the node that is dug
  • If the node above is a tree, it digs it as well.
  • The process is repeated, because the node is dug.
The problem is leaves are not always vertically above the tree, which the code assumes they are.

Re: Code not working

Posted: Mon Jun 30, 2014 17:46
by DevBukkitDude
Thats a piece of the code... The code works mostly, And I do know how it works T_T
I must be getting the error because im used to lua, not lua api

Re: Code not working

Posted: Mon Jun 30, 2014 19:16
by rubenwardy
DevBukkitDude wrote:Thats a piece of the code... The code works mostly, And I do know how it works T_T
I must be getting the error because im used to lua, not lua api
Err, what? That is Lua, not Lua API. All of minetest.* are just functions in minetest = {}

I guess you meant Minetest Lua API.

Re: Code not working

Posted: Thu Jul 03, 2014 16:33
by Calinou
See the default.dig_up() function which is in minetest_next and Carbone: https://github.com/BlockMen/minetest_ne ... s.lua#L273

And an example of a node which is dug upwards when being dug: https://github.com/BlockMen/minetest_ne ... s.lua#L359