Disclaimer: I know how countdowns work, but I am looking for a systematic solution that directly and permanently ties a specific cool-down timer to each sound, instead of setting the timer in every single case where I want the sound to be played.
So I've got a few cases where I don't want certain sounds to play over and over..
E.g. upon spotting the player, my little robot enemies announce their actions based on their current state.
But when I hover at the limit of their sight range, they keep spotting and losing me, and that makes them a little too chatty.
Right now I only check if a sound is already playing before I play it.
My next best idea would be to let a small cooldown timer run every time a sound has been played.
But that would require writing that code everywhere I want the game to play a sound.
So I wonder if there's a smarter way to do it. Maybe I can use a sound object that has an event for each sound with the relevant code in it, so that, from my step events and scripts, I'd only trigger the events?
The problem here is that I've never really used anything except the step and draw events because I write everything else directly in GML. And as far as I understand it, a non-step event for my sound would only run its code a single time when triggered, so a cooldown timer would never actually run out. Now if I set an alarm in this sound event, it would get reset every time the event is triggered, right?
I can't seem to get my head around this at the moment. Help from anyone with experience would be appreciated
Edited by Motorsheep, 28 March 2016 - 02:20 PM.