Mod won't work
Hello, world!
I have tried to make my first mod, which functions as follows: two items will be included - a plain music box, and an 8-bit one. The plain one is made (but does nothing) and can then be crafted into an 8-bit music box with 8 mesecon wires. When left-clicked on, the 8-bit music box will play a tune. Unfortunately, the music will not play upon clicking the box. I have tried to use the debug file produced by the game to correct my code, but after a while I became confused and reverted it to its earlier state.
I have hardly any experience in Lua (less than one session's worth) and this code is based mostly on what I have gathered from reading the Minetest API, combined with C++ experience (I know that the obvious answer would be "learn Lua for a couple of months, THEN write the code.", but I simply do not have the time for a couple of months due to school assignments and other such things.
Here is the code:
Could anybody please tell me what I have done wrong? Thanks!
I have tried to make my first mod, which functions as follows: two items will be included - a plain music box, and an 8-bit one. The plain one is made (but does nothing) and can then be crafted into an 8-bit music box with 8 mesecon wires. When left-clicked on, the 8-bit music box will play a tune. Unfortunately, the music will not play upon clicking the box. I have tried to use the debug file produced by the game to correct my code, but after a while I became confused and reverted it to its earlier state.
I have hardly any experience in Lua (less than one session's worth) and this code is based mostly on what I have gathered from reading the Minetest API, combined with C++ experience (I know that the obvious answer would be "learn Lua for a couple of months, THEN write the code.", but I simply do not have the time for a couple of months due to school assignments and other such things.
Here is the code:
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_craft({
output = '"music_box:plain_music_box" 1',
recipe = {
{'mesecons_noteblock:noteblock','mesecons:wire_00000000_off','mesecons_noteblock:noteblock'},
{'mesecons_button:button_off','bucket:bucket_water','mesecons_button:button_off'},
{'mesecons_gates:and_off','mesecons_hydroturbine:hydro_turbine_off','default:wood'}
}
})
minetest.register_node("music_box:plain_music_box", {
description = "Plain music box",
type = "regular",
diggable = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
tile_images = {"plain_music_box_top.png", "plain_music_box_bottom.png",
"plain_music_box_side.png", "plain_music_box_side.png",
"plain_music_box_side.png", "plain_music_box_side.png"},
inventory_image = minetest.inventorycube("plain_music_box_top.png",
"plain_music_box_side.png", "plain_music_box_side.png"),
})
minetest.register_craft({
output = '"music_box:8-bit_music_box" 1',
recipe = {
{'music_box:plain_music_box','"mesecons:wire_00000000_off" 8',''},
{'','',''},
{'','',''}
}
})
minetest.register_node("music_box:eight_bit_music_box", {
description = "8-bit music box",
type = "regular",
diggable = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
tile_images = {"eight_bit_music_box_top.png", "eight_bit_music_box_bottom.png",
"eight_bit_music_box_side.png", "eight_bit_music_box_side.png",
"eight_bit_music_box_side.png", "eight_bit_music_box_side.png"},
inventory_image = minetest.inventorycube("eight_bit_music_box_top.png",
"eight_bit_music_box_side.png", "eight_bit_music_box_side.png"),
})
minetest.register_on_punchnode(function (pos, node)
if node.type == "music_box:eight_bit_music_box" then
minetest.sound_play("8bit airship (mono)",
{pos = pos, gain = 1.0, max_hear_distance = 40,})
end
end)
Could anybody please tell me what I have done wrong? Thanks!