Presenting an audio sound with certain stimuli but not others

Hi, I’m hoping someone can help me understand the best way to implement this as I’m a beginner to coding and struggling to figure this out. Is it possible to do the below using a coding element in builder?

What are you trying to achieve?:

I have an experiment with 4 visual stimuli (let’s say a square, circle, triangle and star).

In block 1: 2 of these stimuli (square and circle) will each be presented in random order 20 times, with an ITI break between each one.

In block 2: the other 2 stimuli (triangle and star) will be presented in random order 20 times with an ITI break between each one.

I have generated this aspect of the experiment using a loop for the blocks and a nested loop for the stimuli, and it runs as expected.

However, additionally, an audio sound should be paired with 1 of the 2 stimuli in each blocks.

So in block 1: the square should be paired with a sound, but the circle should not. Similarly, in block 2: the triangle should be paired with a sound, the star should not.

However, for the square and the triangle stimuli that have been paired with the sound, the audio sound should only play for 60% of the times when those visual cues are presented. In this experiment, because each stimuli is shown 20 times, that would mean 12 of the times the square or triangle are presented, the sound is played, but 8 of the times it isn’t. This should be randomised, but with some constraints outlined below.

In each block:

  • The first stimuli must always be the one with NO sound (i.e. the circle in block 1, and the star in block 2)
  • For the visual stimuli that are associated with a sound 60% of the time (i.e. the square in block 1 and the triangle in block 2), the first and last time each of these are visual cues are presented in the block must be one of the times the sound is played. So 2 of the 12 times (out of the 60% of 20 trials).

So the sequence would be

Block 1

  • 1st stimuli: Square (no sound)
  • 2nd stimuli: Circle (sound: on)
  • [random sequence of square (no sound) and circle (with sound on 60% and sound off (40%))]
  • Last stimuli: circle (sound: on)

Block 1

  • 1st stimuli: Triangle (no sound)
  • 2nd stimuli: Star (sound: on)
  • [random sequence of Triangle (no sound) and Star (with sound on 60% and sound off (40%))]
  • Last stimuli: Star (sound: on)

I hope that makes sense!