help with turning lights on in minetest (puncher thingy)

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

help with turning lights on in minetest (puncher thingy)

by durtective6 » Wed Nov 20, 2013 17:40

k so ive added a new feature into my mod but when i go to punch it to turn it on, it doesnt turn on. Could someone help and if its needed heres the code

minetest.register_node("techno:techno_lamp", {
description = "techno lamp",
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
tiles = {"techno_lamp.png"},
groups = {choppy=3,cracky=2},
})

minetest.register_node("techno:techno_lamp_on", {
description = "techno lamp",
tile_images = {"techno_lamp.png"},
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
drop = 'techno:techno_lamp',
light_source = 14,
groups = {choppy=3,cracky=3,not_in_creative_inventory=1},
})
minetest.register_craft({
output = '"techno:techno_lamp"',
recipe = {
{'techno:steel_cluster', 'default:cobble', 'techno:steel_cluster'},
{'default:cobble', 'default:glass', 'default:cobble'},
{'techno:steel_cluster', 'default:cobble', 'techno:steel_cluster'},
}
})

local on_light_puncher = function (pos, node, puncher)
if node.name == 'techno:techno_lamp' then
minetest.env:add_node(pos, {name="techno:techno_lamp_on"})
nodeupdate(pos)
elseif node.name == 'techno:techno_lamp_on' then
minetest.env:add_node(pos, {name="techno:techno_lamp",})
nodeupdate(pos)
end
end

also the inventory image is really dark, dunno how to fix that...
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Nov 20, 2013 18:15

You need to register the on punch function like 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
--   Register the function for use.
minetest.register_on_punchnode(on_light_puncher)


A problem that I can see is that the mod lights+ uses that exact same function name for the same purpose for it's lights. A better way to do it is to use the on_punch option in the node registration so that you don't need to use a separate function that is called every time any node is punched. This will save a tiny bit of cpu for people that have super slow machines. It will also be compatible with the mods that make use of the other method that you are trying to use.

NOTE: I did not test your code to see if there was any other problems, I just noticed that you weren't registering the function.

P.S. If you use the on punch part of the node registration, you wont have to check if the node is in fact the one that is getting punched as it will only do it if that node is in fact being punched. :)
Last edited by LionsDen on Wed Nov 20, 2013 18:16, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Nov 20, 2013 18:17

Also, you are likely to be yelled at because this belongs in the modding discussion, not the general discussion.
 

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

by durtective6 » Wed Nov 20, 2013 22:04

Not to be a bother but would i put that line of code anywhere or replace the on_light_puncher part with it?
Last edited by durtective6 on Wed Nov 20, 2013 22:04, edited 1 time in total.
 

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Sun Nov 24, 2013 12:13

LionsDen wrote:A problem that I can see is that the mod lights+ uses that exact same function name for the same purpose for it's lights.

I rewrote Lights+, and it no longer uses on_light_puncher.
durtective6: This code might help you - as LionsDen said, the on_punch code is in the node definition instead of at the end of the init.lua.
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_node(mod:light_off, {
        description = "Light off",
        -- Other stuff here.
        on_punch = function(pos, node, puncher)
            minetest.set_node(pos, {name=mod:light_on})
        end
    })

minetest.register_node(mod:light_on, {
      description = "Light on",
      drop = off,
      -- Other stuff here.
      on_punch = function(pos, node, puncher)
          minetest.set_node(pos, {name=mod:light_off})
      end
})


For the inventory image problem, default:glass uses this in the node definition:
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
inventory_image = minetest.inventorycube("default_glass.png"),
Last edited by qwrwed on Sun Nov 24, 2013 12:14, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 18 guests

cron