Page 1 of 1

[Solved] How do I upload a sound to use when pressing a button?

Posted: Wed Jul 23, 2025 12:02 pm
by yaim904
Hello, today I wanted to use a sound that comes with Factorio, but it is not available for use in mods. So I am trying to load it myself and then call it.
It is not working for me.

Help

The following is the code I am using.

Code: Select all

    ---> data-final-fixes.lua <---
    data.raw["utility-sounds"]["default"]["gui_tool_click"] = {
        filename = "__core__/sound/gui-tool-button.ogg",
        aggregation = { max_count = 3, remove = true }
    }
    
    ---> control.lua <---
    Player.play_sound({ path = "utility/gui_tool_click" })
I'm using what I found in the documentation and some code from Factorio itself, but I must admit that I don't know what I'm doing.

Re: How do I upload a sound to use when pressing a button?

Posted: Thu Jul 24, 2025 10:47 am
by Osmo
The UtilitySounds prototype only holds some predefined sounds. For custom sounds, you beed to define a Sound Protoype https://lua-api.factorio.com/latest/pro ... otype.html

Re: How do I upload a sound to use when pressing a button?

Posted: Thu Jul 24, 2025 9:06 pm
by yaim904
My solution

Code: Select all

---> data-final-fixes.lua <---
data:extend({{
    type = "sound",
    name = "gui_tool_button",
    filename = "__core__/sound/gui-tool-button.ogg"
}})

---> control.lua <---
Player.play_sound({ path = "gui_tool_button" })

Thanks for the message.
The truth is that I solved it on my own, but I forgot to upload it.

Anyway, thank you very much.
Osmo wrote: Thu Jul 24, 2025 10:47 am