| Reference | Downloads | Github

Presenting sound within loop at specific times

Hello everyone,

in my experiment I have a series of tasks within a loop that last around 4 minutes. I want to present a sound at certain times relative to the start of the loop (e.g. 2 minutes after the loop started), but I can not use the trials number as information since the task is self-paced.

For now I have created a sound component in the builder set to start after the end of the routine (after 5 minutes the routine and the loop will be terminated by a piece of code), a clock that start at the beginning of the loop and a code in the “each frame” tab that goes like this:

if (((soundClock.getTime() > 180) && (soundClock.getTime() < 180.02))) {;

so that the program tries to play the sound only on one frame after 2 minutes have been elapsed. I understand that this is a terrible solution! In fact some of the times the sound is not played properly.

Someone have a better solution?


After thinking about it i resolve the issue writing in the “Begin Experiment” tab

sound_1_has_played = false;

and in the “Begin Routine” tab

if ((trials.thisN === 0)) {
    soundClock = new util.Clock();

if (((soundClock.getTime() > 180) && (sound_1_has_played === false))) {;
    sound_1_has_played = true;