Page 1 of 1
making a music mod

Posted:
Wed Oct 28, 2015 18:48
by idfk101
so i changed a bit of the music code for the mesecon noteblock mod and i was wondering if someone had some advice on how to get the music to stop playing when hit again. i want it to play from a list of songs i changed to the directory so it is like an in game sort of pandora playlist i guess. And if theres also a way to maybe set somesort of global variable to be turned off if another noteblock is placed and used while that one is playing
Re: making a music mod

Posted:
Wed Oct 28, 2015 23:31
by qwertymine3
If you only want one block playing (or positionless music) at any given time, AFAIK this shouldn't be too hard.
When you play a sound with minetest.sound_play it should return a 'handle' (a reference to the sound). You can put this in a global variable (just create a variable outside a function) and test that the global is not nil to know if the music is playing. If it is you can then use minetest.sound_stop to stop the music and then set the global to nil.
You may also have to check the song hasn't finished using some form of timer or check against os.clock (store the start time in a global), as I don't think the handle is automatically deleted when the song ends, but I may be wrong.
I haven't tried this, but hopefully this is correct.
Re: making a music mod

Posted:
Wed Oct 28, 2015 23:47
by kaadmy
Re: making a music mod

Posted:
Thu Oct 29, 2015 16:19
by idfk101
so i took your music mod folder lol but it doesnt play anything at all? when i place the block it automatically says disabled by server
Re: making a music mod

Posted:
Thu Oct 29, 2015 18:13
by kaadmy
You need the configuration setting music_enable = true in your minetest.conf, or the file that the config is read from.
Re: making a music mod

Posted:
Fri Oct 30, 2015 03:21
by idfk101
Since you seem to know what youre doing lol how difficult would it be to add some sort of function to play another song after the first ends because right now its the 28 second timer but if i want it to play the next song right after each song ends is that possible? Like i said i sorta want an in game pandora if you will that when you place it it will actually just randomize the music from the sounds folder but im veryyyyy new to lua.