Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Laura Hunt on Sun 05/07/2020 09:31:51

Title: Triggering event according to audio position
Post by: Laura Hunt on Sun 05/07/2020 09:31:51
Like the subject says, I want to trigger an event at a certain point of an audio clip (in this specific case, at the very end). I thought it would be simple enough and that this would do the job:

Code (ags) Select
function room_RepExec()
{
  if (neighborsarguing != null && neighborsarguing.PlayingClip == aNeighbors3 && neighborsarguing.PositionMs == neighborsarguing.LengthMs) {   
    player.Think("I should have some peace and quiet now... at least for a while.");
  }   
}


However, it doesn't seem to be working, as the player's line never gets triggered. I've also tried triggering it at other positions that are not exactly the end of the clip (e.g., neighborsarguing.LengthMs - 1000), but no success either. What could I be doing wrong?

(P.S.: the audio clip is an .ogg file.)
Title: Re: Triggering event according to audio position
Post by: Laura Hunt on Sun 05/07/2020 10:02:44
Of COURSE and as always, as soon as I post my question I find the answer just minutes later (roll)

If the script runs at 60 cycles per second, then each cycle is around 16 ms. This makes it pretty much impossible to nail an exact position in miliseconds.

If I do this (using 32 ms rather than 16 so as to have a bit of a buffer) then it works as intended:

Code (ags) Select
function room_RepExec()
{
  if (neighborsarguing != null && neighborsarguing.PlayingClip == aNeighbors3 && neighborsarguing.PositionMs >= neighborsarguing.LengthMs - 32) {   
    player.Think("I should have some peace and quiet now... at least for a while.");
  }   
}