Jump to content

Recommended Posts

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

image.thumb.png.4cfc861640310d4084d1aadcf29ce194.png

Anyway, any type of help is appreciated.

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 by IronHunter
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

5bce8ba1e1e0a_ScreenShot_20181022214338-copia.png.1e328ff47fc7b6f181c3ccf366bee2fb.png

And in the client_log appears this after it instantly crashes

5bce8ba292eb3_ScreenShot_20181022214635-copia.thumb.png.6ae8ec2912b644df2ab95af9d0bc2457.png

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 by Puka_Picante
More info added
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 by IronHunter
Fixed typo

So, now i added the playlist and the code you did in the dynamic, it crashes because this:

image.thumb.png.e326a68c428fbb2df6963832f1e3aa62.png

 

There's the part where the client log says

image.thumb.png.5f228d385e9478d715d8dfa3560fb6a8.png

The playlist is added at the top of all, is that alright?

image.png.49947acb68fc33a5a3245306e6ee6a2a.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...