Loops cancelling each other out?

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone

What are you trying to achieve?:

I am trying to build an experiment using Builder and am new to coding. (so I apologize if I’m missing something obvious !)

In this experiment, the subject has to click inside a round stimulus, which triggers an audio feedback that is different in every trial. I have several blocks, which each contain 20 sounds played randomly .

For each trial inside a block, the required number of clicks on the stimulus sequentially increases for the audio feedback to appear : at first, one click = sound ; then 2 = sound , then x …

What did you try to make it work?:

The l_clicks loop defines the number or clicks needed, which is handled by an .xlsx file attached to the l_repeats loop (In the nReps$ field, I put the header of the column in the repeats.xlsx file attached to l_repeats ):

l_blocks is attached to a condition file (ChooseBlock.xlsx)
which picks the current block listed under the “Condsfile” header. It actually lists .xlsx files which themselves each list 20 sounds as mentionned above .

Now, I created a loop called trials, and in its condition field, wrote “$Condsfile” (header of ChooseBlocks.xlsx)

And, in the r_feedback routine, which is purely in charge of playing the sounds, I have an audio component. In its “Sound” field, put “$StimFile” , which is the header row of my blocks file.

What specifically went wrong when you tried that?:

The experiment runs, but not as I would like it to.

When I place the trials loop inbetween the l_repeats and l_blocks ones, the number of required clicks indeed increases as planned, BUT the sound played is always the same.

When I place trials inside the other two, the sounds which are played changed every time, BUT the required clicks don’t, ie. it’s always one click = one sound.

----> Is there a way to get the best of both worlds ?
== Make the required amount of clicks AND the sound that is played change in each trial ?

I’m thinking there must something more elegant and efficient to do than those 3 outer loops but I have trouble coming up with the means to achieve it, so I’ll be thankful if anyone could point me in the right direction.

Hi there !
A little update.

I thought the way around this would be to delete the l_repeats loop and instead use a list.
That is, create a list out of my repeats.xlsx file which lists the incremental nReps for the l_clicks loop. Then, for every trial, the index of the number picked out of the list would increase by 1 (as if I’d go down my excel file)

So I figured this code component would do it :
image
(repvalue being what’s in the nReps field of my l_clicks loop)

Of course, in order for a new value of repvalue to be picked on every trial, I added a code in my r_feedback routine that updates the value of numberlist

numberlist=numberlist + 1

Still trying to figure out the details, since I added a new time-out conditional routine, but it seems to be a working alternative to the endless loop design.

Last thing,

I created a routine called “initialize” in which I put the repvalue update, otherwise it will update during the loop and loop twice the first time instead of once.
The fix is to add a code component in this initialize routine, and in the Begin Routine tab :

repvalue = repetitionlist [numberlist] 

Everything works fine now !
Hope this can be of use to some of you.