Code not working

Post Reply
User avatar
DevBukkitDude
New member
Posts: 8
Joined: Wed Jun 11, 2014 21:57
In-game: DevBukkitDude

Code not working

by DevBukkitDude » Post

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)
Linux, Linux, Mac, Linux,Linux
^
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Notice mac is there?
Great for developers!

Win is crap

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

Re: Code not working

by rubenwardy » Post

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.

User avatar
DevBukkitDude
New member
Posts: 8
Joined: Wed Jun 11, 2014 21:57
In-game: DevBukkitDude

Re: Code not working

by DevBukkitDude » Post

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
Linux, Linux, Mac, Linux,Linux
^
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Notice mac is there?
Great for developers!

Win is crap

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

Re: Code not working

by rubenwardy » Post

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.

User avatar
Calinou
Moderator
Posts: 3162
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

Re: Code not working

by Calinou » Post

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest