How to add a custom sound for a mod

User avatar
RoyallyRaincow
New member
 
Posts: 2
Joined: Thu Mar 03, 2016 17:08
GitHub: EpicSnivyAble
In-game: TheRoyalRaincowDash

How to add a custom sound for a mod

by RoyallyRaincow » Wed Mar 30, 2016 03:36

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
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: How to add a custom sound for a mod

by LNJ » Wed Mar 30, 2016 08:32

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.
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

User avatar
RoyallyRaincow
New member
 
Posts: 2
Joined: Thu Mar 03, 2016 17:08
GitHub: EpicSnivyAble
In-game: TheRoyalRaincowDash

Re: How to add a custom sound for a mod

by RoyallyRaincow » Wed Mar 30, 2016 18:18

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
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron