Page 1 of 1

How to add a custom sound for a mod

PostPosted: Wed Mar 30, 2016 03:36
by RoyallyRaincow
S, I've been working on a mod (duh), and I want to add a custom sound for the block entity when walked on. I did this correctly back in MT 4.11, and it worked (never published the mod so I lost it). I used a small, edited version of the default sound registration, which worked then. I do the same thing now and I keep getting errors that pop up at random times. What I've been trying is:
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
function pm.node_sound_defaults(table)
   table = table or {}
   table.footstep = table.footstep or
         {name = "pm_block_step", gain = 1.0}
   table.dug = table.dug or
         {name = "pm_block_dug", gain = 0.25}
   return table
end


From the debug.txt:
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
========== ERROR FROM LUA ===========
2016-03-29 22:31:15: ERROR[main]: Failed to load and run script from
2016-03-29 22:31:15: ERROR[main]: C:\Games\Minetest\bin\..\mods\pm\init.lua:
2016-03-29 22:31:15: ERROR[main]: C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: attempt to index global 'pm' (a nil value)
2016-03-29 22:31:15: ERROR[main]: stack traceback:
2016-03-29 22:31:15: ERROR[main]:    C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: in main chunk
2016-03-29 22:31:15: ERROR[main]:    [C]: in function 'dofile'
2016-03-29 22:31:15: ERROR[main]:    C:\Games\Minetest\bin\..\mods\pm\init.lua:1: in main chunk
2016-03-29 22:31:15: ERROR[main]: ======= END OF ERROR FROM LUA ========
2016-03-29 22:31:15: ERROR[main]: Server: Failed to load and run C:\Games\Minetest\bin\..\mods\pm\init.lua
2016-03-29 22:31:15: ERROR[main]: ModError: ModError: Failed to load and run C:\Games\Minetest\bin\..\mods\pm\init.lua
2016-03-29 22:31:15: ERROR[main]: Error from Lua:
2016-03-29 22:31:15: ERROR[main]: C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: attempt to index global 'pm' (a nil value)
2016-03-29 22:31:15: ERROR[main]: stack traceback:
2016-03-29 22:31:15: ERROR[main]:    C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: in main chunk
2016-03-29 22:31:15: ERROR[main]:    [C]: in function 'dofile'
2016-03-29 22:31:15: ERROR[main]:    C:\Games\Minetest\bin\..\mods\pm\init.lua:1: in main chunk
2016-03-29 22:31:15: ERROR[main]: Check debug.txt for details.


I'm not understanding what I've done wrong, so can you help me please?

~ The Royal Raincow Dash

Re: How to add a custom sound for a mod

PostPosted: Wed Mar 30, 2016 08:32
by LNJ
This means that the (global) variable pm is not defined. You have to define it first, because Lua don't knows the variable and you have only specified a sub-variable (node_sound_defaults).
C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: attempt to index global 'pm' (a nil value)

Add this at the top:
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
pm = {}

or if you only want to use the variable in this file then:
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 pm = {}


nil equals a None in python, and a NULL in C/C++ and it only means that the variable is not defined.

Re: How to add a custom sound for a mod

PostPosted: Wed Mar 30, 2016 18:18
by RoyallyRaincow
LNJ wrote:This means that the (global) variable pm is not defined. You have to define it first, because Lua don't knows the variable and you have only specified a sub-variable (node_sound_defaults).
C:\Games\Minetest\bin\..\mods\pm/sounds.lua:1: attempt to index global 'pm' (a nil value)

Add this at the top:
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
pm = {}

or if you only want to use the variable in this file then:
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 pm = {}


nil equals a None in python, and a NULL in C/C++ and it only means that the variable is not defined.


Thanks! Will try :P