How would one add new sound effects?

Place to get help with not working mods / modding interface.
0xConnery
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Aug 07, 2017 11:57 pm
Contact:

How would one add new sound effects?

Post by 0xConnery »

I hope this hasn't been posted before, but I'm wondering what the best and easiest way of adding your own SFX is.
Judging from what I have read through so far during the past week, there is not too much documentation present regarding the sound system of Factorio and for me, who wants to add new SFX, it seems rather difficult to have their goal come a reality.

For instance, I tried to add my sounds under the utility category - only to find out that it is hardcoded and that the protoype page is incomplete :(

Up to this point I managed with adding my sfx under the ambient category, but the drawback of this is that the tracks are being played at random.

So, how would I usually do this?
Is using a category actually the way I should choose?
How would I go about adding my sound in the dataphase, or more precisely, where would I do that in regards of tha data.raw structure?
How would I then access the sound during runtime in control.lua space?


Huge thanks in advance!
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How would one add new sound effects?

Post by Klonan »

0xConnery wrote: Tue Dec 17, 2019 10:43 am I hope this hasn't been posted before, but I'm wondering what the best and easiest way of adding your own SFX is.
Judging from what I have read through so far during the past week, there is not too much documentation present regarding the sound system of Factorio and for me, who wants to add new SFX, it seems rather difficult to have their goal come a reality.

For instance, I tried to add my sounds under the utility category - only to find out that it is hardcoded and that the protoype page is incomplete :(

Up to this point I managed with adding my sfx under the ambient category, but the drawback of this is that the tracks are being played at random.

So, how would I usually do this?
Is using a category actually the way I should choose?
How would I go about adding my sound in the dataphase, or more precisely, where would I do that in regards of tha data.raw structure?
How would I then access the sound during runtime in control.lua space?


Huge thanks in advance!
You need to just add it as a sound prototype:
name of a sound prototype defined in the data phase
The prototype would look like this:

Code: Select all

{
  type = "sound",
  name = "name-of-the-sound",
  filename = "__base__/etc/etc.ogg"
}
0xConnery
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Aug 07, 2017 11:57 pm
Contact:

Re: How would one add new sound effects?

Post by 0xConnery »

Heya, thanks for the help!
What is now unclear for me is whether, and if so, where to add the newly created prototype.

I am not sure whether the pure creation of a prototype is sufficient or whether storing the prototype somewhere in some table during data phase is required.

To give more context, I am using a function to register all my sounds and so far, it looks (roughly) like this:

Infix and key_filename_table are arguments, type_name is "sound"

Code: Select all

	local prefix = Settings.sound.folder_location
	local postfix = Settings.sound.file_type

	local category = Settings.sound.category
	local type_name = Settings.sound.type_name

	for key,value in pairs(key_filename_table) do
		data[Settings.mod_category][category][key] = {
			name = key,		
			filename = prefix .. infix .. value .. postfix,		
			type = type_name
		}
	end
But using a soundpath which would equal any of the used keys in the block above is not working. More precisely, I'm attempting to use LuaPlayer::play_sound{path = key} and I have the strong feeling that there's something I do not yet understand because it is unclear to me in what way the game "collects" my added data and whether the table I added is actually considered during collection or discarded as a whole.
0xConnery
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Aug 07, 2017 11:57 pm
Contact:

Re: How would one add new sound effects?

Post by 0xConnery »

So, I felt a littly guilty that I didn't look everywhere for a solution and took a look at the data repo of the game.
The game adds sounds in the following way (at the moment / 0.17):

Code: Select all


data:extend
{
  {
    type = "sound",
    name = "worm-sends-biters",
    variations = { filename = "__base__/sound/creatures/worm-roar-alt-3.ogg", volume = 1 }
  },
  {
    type = "sound",
    name = "mainframe-activated",
    variations = { filename = "__core__/sound/wire-pickup.ogg", volume = 2 }
  },
  {
    type = "sound",
    name = "car-repaired",
    variations = { filename = "__base__/sound/car-repaired.ogg", volume = 0.6 }
  },
}
So, with a little adaption, I should be able to do the same.
0xConnery
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Aug 07, 2017 11:57 pm
Contact:

Re: How would one add new sound effects?

Post by 0xConnery »

Works!

This is something I should have definitely stumbled upon sooner, but hopefully this thread will be insightful for other aspiring modders :D
Post Reply

Return to “Modding help”