help interigating with mesecons

builderjer
New member
 
Posts: 5
Joined: Mon Nov 26, 2012 08:02

help interigating with mesecons

by builderjer » Mon Nov 26, 2012 16:12

I am trying to write a mod which will interigate with the mesecons mod. I can get my mod to recognize the mesecons and turn on and off with them, but when i try and connect a messecon to my mod, the new mesecon will not recognize that it is connected to a powered node.

I know that my code is not the cleanest and probably a lot of bugs and better ways to accomplish the same thing, but any information on what I am doing wrong is greatly apreaciated.

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
-- sl_base

VERSION = "0.0.1"

minetest.register_node("sl_base:concrete_off", {
    drawtype = "normal",
    description = "Street Lamp - Concrete Base",
    tiles = sl_tiles.concrete_off,
    groups = {cracky=3, mesecon=3},
   
     after_place_node = function(pos, placer)
        local node = minetest.env:get_node(pos)
        if sl_check_power(pos, mesecon:get_rules(node.name)) then
            minetest.env:add_node(pos, {name="sl_base:concrete_on"})
            mesecon:turnon(pos)
        end
--          local node = minetest.env:get_node(pos)
--          local rules = mesecon:conductor_get_rules(node)
--         print(node.name)
--          for i, rule in ipairs(rules) do
--              local np = {}
--              np.x = pos.x + rule.x
--              np.y = pos.y + rule.y
--              np.z = pos.z + rule.z
--             local n = minetest.env:get_node(np)
-- --            if mesecon:is_receptor
-- --            if mesecon:is_powered(np) then
--             if mesecon:connected_to_pw_src(np) then
--                 mesecon:turnon(pos)
--                 nodeupdate(pos)
--                 mesecon:receptor_on(pos)
--             end
--          end
     end,
   
    after_dig_node = function(pos, oldnode, oldmetadata, digger)
    end,
       
})

minetest.register_node("sl_base:concrete_on", {
    drawtype = "normal",
    description = "Street Lamp - Concrete Base",
    tiles = sl_tiles.concrete_on,
    groups = {cracky=3, mesecon=3, not_in_creative_inventory=1},
    drop = "sl_base:concrete_off",
   
    after_dig_node = function(pos, oldnode, oldmetadata, digger)
        local node = minetest.env:get_node(pos)
        local rules = mesecon:get_rules("sl_base:concrete_on")
        for i, rule in ipairs(rules) do
            local np = {}
            np.x = pos.x + rule.x
            np.y = pos.y + rule.y
            np.z = pos.z + rule.z
            local name = minetest.env:get_node(np).name
            print("here i am "..name)
            if name ~= "air" and not sl_check_power(np, mesecon:get_rules(name)) then
                if not mesecon:connected_to_pw_src(np) then
                    mesecon:turnoff(np)
                end
            end
        end
    end,
})
   
mesecon:register_conductor("sl_base:concrete_on", "sl_base:concrete_off", mesecon:get_rules("sl_base:concrete_off"))

print("[Street Lamp] -- sl_base -- loaded.  Version: "..VERSION)
 

builderjer
New member
 
Posts: 5
Joined: Mon Nov 26, 2012 08:02

by builderjer » Mon Dec 03, 2012 01:10

does no one know what I am doing wrong? I sure could use some help on this
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Mon Dec 03, 2012 07:30

Please be patient. If no one responded, it's not because they don't care; it's because no one has the answer yet. If someone did, he or she would gladly help you. Thanks for understanding.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

klunk
 

by klunk » Mon Dec 03, 2012 10:27

There is no clue of what is going wrong in in your ./minetest/debug.txt ?
 

Doc
Member
 
Posts: 75
Joined: Sun Nov 04, 2012 00:21

by Doc » Tue Dec 04, 2012 03:06

I will help you. I assume you are trying to conduct mesecons from concrete_base block to the top of a street lamp, and turn it on when mesecon signal is applied. Mesecons has a few operations for signal reaction.
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 swap_node = function(pos, name)
    local node = minetest.env:get_node(pos)
    local data = minetest.env:get_meta(pos):to_table()
    node.name = name
    minetest.env:add_node(pos, node)
    minetest.env:get_meta(pos):from_table(data)
end
(the swap node function)


mesecon:register_on_signal_on(function(pos, node)
    if node.name ~= "sl_base:concrete_off" then
        return
    end

    swap_node(pos, "sl_base:concrete_on")

end)
(if mesecons is on, make it on)

mesecon:register_on_signal_off(function(pos, node)
    if node.name == "sl_base:concrete_on" then
        swap_node(pos, "sl_base:concrete_off")
    end
(If mesecons is off, then make it off.)

minetest.register_abm({
     frequency = 1,
     chance = 1,
     nodenames = {street_lamps:streetlamp_off}, (switch with actual name)
     (other variables here)
     action = function(pos)
          if minetest.env:get_node({x=pos.x, y=pos.y-1, z = pos.z-1}).name() == "sl_base:concrete_on" then
                    minetest.env:set_node(pos, {name="lamp_on"}) (I think that is how you set_node lol)
          end
end,
})
minetest.register_abm({
     frequency = 1,
     chance = 1,
     nodenames = {street_lamps:streetlamp_on}, (switch with actual name)
     (other variables here)
     action = function(pos)
          if minetest.env:get_node({x=pos.x, y=pos.y-1, z = pos.z-1}).name() == "sl_base:concrete_off" then
                    minetest.env:set_node(pos, {name="lamp_off"}) (I think that is how you set_node lol)
          end
end,
})


This registers an abm that changes the streetlamp segment to on if the block under it is concrete_on. Just copy and paste it to make it off, etc.

Hope it helps :)
Last edited by Doc on Tue Dec 04, 2012 03:06, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 8 guests

cron