Mod won't work

User avatar
Thaizasaskand
New member
 
Posts: 7
Joined: Thu Nov 01, 2012 09:04

Mod won't work

by Thaizasaskand » Thu Nov 01, 2012 14:05

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:

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!
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Thu Nov 01, 2012 18:24

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
    if node.type == "music_box:eight_bit_music_box" then

I guess that's the bug. It should be node.name, not node.type.
you should also better use
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
on_punch = function (pos, node, puncher)
    minetest.sound_play("8bit airship (mono)", ...)
end,

inside the node definition.

Everything else looks quite good. I hope I could help you!
Last edited by Jeija on Thu Nov 01, 2012 18:25, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
Thaizasaskand
New member
 
Posts: 7
Joined: Thu Nov 01, 2012 09:04

by Thaizasaskand » Sun Nov 04, 2012 16:23

Hi.
Thanks very much for the advice! I changed the "type" to "name" as you suggested. I am a bit stupid to understand the second bit, sorry. Would you be able to post me the whole lot code for the relevant part, please? Thanks for the help!


Thanks also, Jeija, for mesecons - they're great! Me and my sister both love it!
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Mon Nov 05, 2012 18:45

There you go:

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("music_box:eight_bit_music_box", {
    description = "8-bit music box",
    type = "regular",
    diggable = true,
    on_punch = function (pos, node, puncher)
        minetest.sound_play("8bit airship (mono)",
        {pos = pos, gain = 1.0, max_hear_distance = 40,})
    end,
    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"),
        })


You can now just remove the register_on_punchnode part and replace the old node registration by this one.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
Thaizasaskand
New member
 
Posts: 7
Joined: Thu Nov 01, 2012 09:04

by Thaizasaskand » Sat Nov 17, 2012 11:50

Sorry for late reply: thanks for this. Something still won't work, though. I shall upload the mod as a zip archive. If I am to upload a .zip archive containing the modification to the web, could anybody please tell me what is wrong?

https://www.4shared.com/zip/rkMVlMx3/music_box.html
 


Return to WIP Mods

Who is online

Users browsing this forum: Bing [Bot] and 4 guests

cron