Disclaimer:
Alright, so,
Like it is common practice to place all your sprites on a sprite sheet, I have tried to do the same with audio.
I have all my sound effects relevant to combat in my naval battle game on one audio track.
Now, before we continue, I've got to say the problem I'm having has *nothing* to do with the fact I have all my audio on one track, rather, this trick is pretty efficient and expedites download times in certain edge cases.
So yes, I am using this, and separating them isn't going to fix the problem.
I have looked everywhere for this question, so I apologize if this was asked before, (It has been but unfortunately the person that was having trouble wasn't as experienced in C2-3 & in their case of this problem happening, the solution given to them was far less precise than what my problem requires.)
Now, with that out of the way, what is the problem I'm having?:
When you play a sound, you associate that sound with a tag, that way you can stop specific *groups* of that audio-by-tag or modify them.
This is where the problem starts, for sounds that play frequently stopping audio of a specific tag stops ALL audio of that tag, which is to be expected yes, but frustrating.
Let me go further into detail to give some more context, why am I stopping sounds?
I have a cannon firing SFX, this will inevitably play so many times that the volume will increase exponentially until the sound ends, which, by the way, isn't one specific sound effect because all of them are stored on the same file.
The obvious solution is playing them as separate audio like I said above that I wouldn't be doing, but, for development's sake its much faster for me to keep them in one place as I happen to be the one that produces these sounds, which is the other reason.
What I've tried:
1.)
So, I have to create an audio limiter, that counts the number of times a tag is played and attempts to clamp it so that no new sounds are being played at the same duration.
But predictably I can only do this by adding a number to each tag, and randomizing when a sound should stop.
I.E
play SFX "shoot" & round(random(1, 4))
if shoot is playing & duration >= 4 seconds (length of that specific section of audio) stop SFX "shoot" & round(random(1,4))
The problem with this is, there is a chance that this does not stop the audio, and so it continues playing until this function is ran again, and the dice finally lands on stopping that audio of that tag.
2.)
I was thinking I could probably combine the is playing condition and specify in its expressions box that if a tag is playing,
"SFX" is playing & audio.duration >= 4, stop the audio.
Does not work, seems to ignore the expression as though the condition only cares about the first valid tag thrown in there, never mind the fact there is a logical AND checking to see if that audio reached a certain duration.
Kind of disappointing, but then again, it's likely I'm doing that wrong and that it is in-fact possible.
3.)
Google's AI told me you can stop the last played instance of a sound by using an empty tag "".
Uh, tried it and it did nothing, I'm guessing this isn't a thing.
Even if it were, I think this would also stop anything else playing recently, of any tag instead of specifically what I want it to stop.
Shame.
Verdict:
In my opinion it would be far more efficient if there was a way to look for a tag, and have the option to test for duration, or some way to instance specific instances of a tag.
If you could stop an audio track of tag by AGE or something, so much better than stopping ALL instances of that sound, or trying to roll some dice to split them up into instances.
If I had separated my sounds, ultimately Id STILL run into this problem, except for individual sounds.
Before you ask how it's possible for a single sound to play *that* many times where even separating audio into variations isn't enough:
I want you to picture 20 ships on your side, 20 ships on the NPC side, each ship can have upwards of 50 cannons (technically it's just 20 turrets (1 for each ship), but I have a formula that divides the rate of fire according to the number of guns a ship has) this number comes from a number value stored in a ship and youll quickly reach 100 or so instances of that tag playing within a minute of firing.
to be clear a ship, is just 2 instances, Im not literally adding 50 turrets to each ship, its just clever math and fire rate manipulation on one turret per ship.
I'm not going to reduce the scope of my battles because it's a key part of the game's identity, or it will be.
So, I'm posting this here hoping there is an elegant solution to this that I haven't thought of.
Of course, I'll still be trying stuff out in the background like I usually do with these posts, because I do have to wait for a response and obviously there's a chance Ill close the post early if I find a solution on my own.
Oh, I'm open to using plugins or Javascript to achieve the desired effect, so if what I'm doing isn't possible throw me some suggestions on what I can do to force a solution with these options.