[1.1.34] play_sound{...} not playing sound globally

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
Post Reply
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 310
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

[1.1.34] play_sound{...} not playing sound globally

Post by Stringweasel »

I'm trying to play a sound that's heard globally, ideally only for specific players. According to the docs if I don't supply a position argument then it's played "everywhere". However, when I play the sound and walk away the sound volume lowers, and disappear if I'm far enough away. I expect the volume to stay constant because I don't supply a position.

I tried this using surface and player and observed no difference. Also, I'm playing the siren sound which is quite long.

Reproduce

Load the little mod that simply creates a SoundPath for the siren sound. Then type the following console command:

Code: Select all

/c game.player.surface.play_sound{path="siren"}
or

Code: Select all

/c game.player.play_sound{path="siren"}
You will hear the sound. Walk away, and the sound volume will lower and eventually dissapear if you're far enough away.
Attachments
SoundTest_0.0.1.zip
(503 Bytes) Downloaded 145 times
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

Rseding91
Factorio Staff
Factorio Staff
Posts: 13173
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.34] play_sound{...} not playing sound globally

Post by Rseding91 »

Thanks for the report. Currently this is how sounds work: when a sound is played it gets played at a position (in this case the player position) and since it's not tied to a specific entity the position stays where it was created. Maybe the name could be updated or the docs updated to mention that it plays at the player(s) position so if they move and the sound is long it doesn't move with them.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 310
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [1.1.34] play_sound{...} not playing sound globally

Post by Stringweasel »

I understand, that is unfortunate. I will make a note later in Bilka's thread that the docs should be updated.

So, there is no way in Lua to mimic a programable speaker that plays the siren sound consistently and heard everywhere, except for building a physical programmable speaker entity and setting it to play the siren? This will cause all players to hear it, but I can live with that. I'd rather have the sound consistent.

Thanks for having a look at it Rseding!
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: [1.1.34] play_sound{...} not playing sound globally

Post by boernsen2 »

Did you find any way to play a custom sound globally for all players and position-independently?

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 310
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [1.1.34] play_sound{...} not playing sound globally

Post by Stringweasel »

boernsen2 wrote:
Sun Apr 10, 2022 11:25 am
Did you find any way to play a custom sound globally for all players and position-independently?
I decided it was out-of-scope for me, but someone did make a good suggestion to me. Spawn a speaker and let the speaker play the sound somehow. A speaker can be set to play global, and will stay global even if you move around. And if you're doing data-stage as well you could create an invisible speaker to use. Spawn it somewhere and after the sound is done delete it again. Or create a single one that's the dedicated sound maker, depends on your implementation. Never tried it though.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: [1.1.34] play_sound{...} not playing sound globally

Post by boernsen2 »

Just for reference, I just found a solution accidentally!!! :)

I stumbled over this:
https://wiki.factorio.com/Prototype/Sou ... e_modifier

Just configure your sound with an exorbitantly high audible_distance_modifier in data.lua, e.g.

Code: Select all

data:extend({
  {
    type = "sound",
    name = "my_sound",
    filename = "__ModName__/my_sound.ogg",
    category = "gui-effect",
    volume = 1.0,
    audible_distance_modifier = 1e20
  }
})
Then use it as usual with any of these:
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound

Thanks for all your inspriation!! :)

Post Reply

Return to “Minor issues”