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...
help with turning lights on in minetest (puncher thingy)
- durtective6
- Member
- Posts: 186
- Joined: Sun Aug 12, 2012 14:19
- In-game: derplez or BlockFrog
- Location: a shed in the desert
help with turning lights on in minetest (puncher thingy)
I'm still here, last time I checked at least.
You need to register the on punch function like this:
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.
Code: Select all
-- Register the function for use.
minetest.register_on_punchnode(on_light_puncher)
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.
- durtective6
- Member
- Posts: 186
- Joined: Sun Aug 12, 2012 14:19
- In-game: derplez or BlockFrog
- Location: a shed in the desert
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.
I'm still here, last time I checked at least.
I rewrote Lights+, and it no longer uses on_light_puncher.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.
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.
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
})
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.
Who is online
Users browsing this forum: cuthbertdoublebarrel and 6 guests