play_sound{} in scenarios

Place to get help with not working mods / modding interface.
Post Reply
der-dave.com
Inserter
Inserter
Posts: 28
Joined: Sat May 07, 2016 3:57 pm
Contact:

play_sound{} in scenarios

Post 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?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: play_sound{} in scenarios

Post 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"})
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

der-dave.com
Inserter
Inserter
Posts: 28
Joined: Sat May 07, 2016 3:57 pm
Contact:

Re: play_sound{} in scenarios

Post 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? :)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: play_sound{} in scenarios

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

der-dave.com
Inserter
Inserter
Posts: 28
Joined: Sat May 07, 2016 3:57 pm
Contact:

Re: play_sound{} in scenarios

Post by der-dave.com »

Many thanks for your explanation :)

Post Reply

Return to “Modding help”