Page 1 of 1

play_sound{} in scenarios

Posted: Thu Oct 04, 2018 4:52 pm
by der-dave.com
Hello devs,

I`m wondering why it is not possible to play custom sounds in a custom scenario and only possible by using mods.
Or am I wrong? Then, can you Show me how to do this?

Re: play_sound{} in scenarios

Posted: Thu Oct 04, 2018 5:24 pm
by eradicator
At least two built-in scenarios use play_sound. You're probably using a wrong path. Post code that isn't working.
Example from team_production.lua:

Code: Select all

player.play_sound({path = "utility/game_lost"})

Re: play_sound{} in scenarios

Posted: Thu Oct 04, 2018 5:35 pm
by der-dave.com
Thank you for your quick reply:

Here a short overview of my code:

Soundfile is located at: "sounds/wololo.wav"
Its added as "wololo" via "data.lua", which is located in root dir:

Code: Select all

--sounds
data:extend(
    {
        {
            type = "sound",
            name = "wololo",
            filename = "__new-scenario__/sounds/wololo.wav",
            volume = 1.0
        }
    })
The Sound should be played when joining the game. This is done via "player_joined" event in "control.lua", which is located in root dir:

Code: Select all

player.surface.play_sound{path = "wololo"}
Maybe I have to edit the "filename" attribute and add the basedir? How to do this?



EDIT

I think I found the reason for that (without solution):
https://wiki.factorio.com/Types/FileName
Ist currently not possible to define the path to be in a fcenario folder. Only "core", "base" and "mod" is supported. Thats a bit unlucky. Wube, can you confirm this? Better: Can you change this to also support scenario folders? :)

Re: play_sound{} in scenarios

Posted: Fri Oct 05, 2018 7:57 am
by eradicator
Scenarios don't have access to the data stage, and that is higly unlikely to ever change because they need to be run without restarting the game. So you'll have to make a seperate mod (e.g. "Dave's Scenario Sounds Library" or something) to add the sound if you want to use it during a scenario.

Re: play_sound{} in scenarios

Posted: Fri Oct 05, 2018 8:01 am
by der-dave.com
Many thanks for your explanation :)