Puka_Picante Posted October 22, 2018 Share Posted October 22, 2018 I would like to know if someone knows how to add 2 songs in the dynamicmusic.lua or if it's a more easy way in the Fmod files, making them to have a chance of 50/50 to play. I already tried with a very poor way Anyway, any type of help is appreciated. Link to comment Share on other sites More sharing options...
IronHunter Posted October 22, 2018 Share Posted October 22, 2018 (edited) I guess one method you can do is to store your strings in a table: then call them using a math.random style function: function GLOBAL.randomindex(t) --Selects a random item from a table local keys = {} for key, value in pairs(t) do keys[#keys+1] = key --Store keys in another table end local index = keys[math.random(1, #keys)] return t[index] end you can place this in modmain then call it anywhere as randomindex(table) it'll return 1 key at random from your table --make a table accessable to your soundemitter: local playlist = { "Doukutsu no Oku", "Kemonotachi no Ikidukai", } --I am not 100% sure how music is called but this is how you can do it at least for sounds SoundEmitter:PlaySound("kemonosoundtrack/music/"..randomindex(playlist), ourmusicvariable) Edit: I also suggest to use simpler variable names for your songs etc, as it makes it much less likely for typos or other human errors when coding. Edited October 22, 2018 by IronHunter Link to comment Share on other sites More sharing options...
Puka_Picante Posted October 23, 2018 Author Share Posted October 23, 2018 Thank you so much, i know it's a bit messy with those names, but my Toc. makes me name them exactly like the original song Link to comment Share on other sites More sharing options...
Puka_Picante Posted October 23, 2018 Author Share Posted October 23, 2018 (edited) 8 hours ago, IronHunter said: I guess one method you can do is to store your strings in a table: then call them using a math.random style function: function GLOBAL.randomindex(t) --Selects a random item from a table local keys = {} for key, value in pairs(t) do keys[#keys+1] = key --Store keys in another table end local index = keys[math.random(1, #keys)] return t[index] end you can place this in modmain then call it anywhere as randomindex(table) it'll return 1 key at random from your table --make a table accessable to your soundemitter: local playlist = { "Doukutsu no Oku", "Kemonotachi no Ikidukai", } --I am not 100% sure how music is called but this is how you can do it at least for sounds SoundEmitter:PlaySound("kemonosoundtrack/music/"..randomindex(playlist), ourmusicvariable) Edit: I also suggest to use simpler variable names for your songs etc, as it makes it much less likely for typos or other human errors when coding. Ahm, i don't know if this is right or not, i'm trying to add the code of the randomindex in the dynamicmusic.lua And in the client_log appears this after it instantly crashes Sorry for that, but i'm not so experienced at this nor know if it can be added in the dynamic music or it has to be yes or yes a remap sound event or sound emitter Edited October 23, 2018 by Puka_Picante More info added Link to comment Share on other sites More sharing options...
IronHunter Posted October 23, 2018 Share Posted October 23, 2018 (edited) if _innightmare then _soundemitter:PlaySound("dontstarve/music/music_work_ruins") elseif _iscave then _soundemitter:PlaySound("kemonosoundtrack/music/"..randomindex(playlist), "ourmusicvariable") else _soundemitter:PlaySound(SEASON_BUSY_MUSIC[phase][season],"busy") end I think a better method is to use if statements instead, this is really cluttered a quick check of the dynamicmusic shows them doing this method. I mean you can try using the other method, but it is so much more legible this way. I can't make heads or tails of your error log, as I don't know what that line 170 is referencing, but it looks like one of your brackets is in the wrong spot based on the error. Edited October 24, 2018 by IronHunter Fixed typo Link to comment Share on other sites More sharing options...
Puka_Picante Posted October 24, 2018 Author Share Posted October 24, 2018 So, now i added the playlist and the code you did in the dynamic, it crashes because this: There's the part where the client log says The playlist is added at the top of all, is that alright? Link to comment Share on other sites More sharing options...
IronHunter Posted October 24, 2018 Share Posted October 24, 2018 I made a typo sorry, difficult to type on mobile. The closing bracket was in the wrong place. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now