Page 1 of 1

Node detection

Posted: Thu Aug 16, 2018 15:25
by GamingAssociation39
I'm looking for a way to change the nodes when placed next to a similar node. The code below is something that JosiahWI had whipped up but I can't figure out how to get it working.

Code: Select all

minetest.register_abm({
    name = "ma_pops_furniture:table_wood",
    abm = function(node, otherArgs)
        if minetest.get_node{pos.x+1, pos.y, pos.z}.name == "ma_pops_furniture:table_wood" then
            minetest.set_node(pos, "ma_pops_furniture:table_c2_wood")
        elseif minetest.get_node{pos.x+1, pos.y, pos.z}.name == "ma_pops_furniture:table_wood" then
            minetest.set_node(pos, "ma_pops_furniture:table_c2_wood")
        elseif minetest.get_node{pos.x+1, pos.y, pos.z}.name == "ma_pops_furniture:table_wood" then
            minetest.set_node(pos, "ma_pops_furniture:table_c2_wood")
        elseif minetest.get_node{pos.x+1, pos.y, pos.z}.name == "ma_pops_furniture:table_wood" then
            minetest.set_node(pos, "ma_pops_furniture:table_c2_wood")
        end
    end
})

Re: Node detection

Posted: Thu Aug 16, 2018 15:29
by rubenwardy
1. set_node takes a node, not a node name. So { name = "ma_pops_furniture:table_c2_wood" } not "ma_pops_furniture:table_c2_wood"

2. use parentheses when calling a function like so minetest.get_node({pos.x+1, pos.y, pos.z}).name. Every time you miss the parentheses, a puppy dies

Re: Node detection

Posted: Fri Aug 17, 2018 06:55
by ChimneySwift
Is it just me or are you checking the exact same thing 4 times?

Re: Node detection

Posted: Fri Aug 17, 2018 09:36
by rubenwardy
Yeah, and it's also not a valid position