Insert catch trials into a loop

Hi,

I have a loop where words appear. After every 4 words a catch trial (one of two other words) should appear. For this I have created a new routine inside the loop with the following code components in the Tab Each Frame:

if WordCheck_trials.thisN == 0 or WordCheck_trials.thisN % 4 != 0: continueRoutine = False

catchWord = random.choice(('fragen','meinen'))

and for JS

if (((WordCheck_trials.thisN === 0) || ((WordCheck_trials.thisN % 4) !== 0))) { continueRoutine = false; }

function random_character() { var chars = "pq"; return chars.substr( Math.floor(Math.random() * 2), 1); } if (random_character()==="p") { catchWord = "fragen"; } else { catchWord = "meinen"; }

I added $catchWord to my text component. On Psychopy it doesn´t work. On Pavlovia the catch trial occur after each trial and not after every 4th trial.

I also tried to include the catch words in my excel file and using only
if WordCheck_trials.thisN == 0 or WordCheck_trials.thisN % 4 != 0: continueRoutine = False This works on Psychopy but not on Pavlovia.

I have another loop with a break. For the break I´m using the same code and it works fine.

Thanks!

Please search the forum for my crib sheet.

Online, all loops must be referred to as trials, irrespective of their actual name.

Thank you very much for your quick reply!
I have changed the loop name in the code to trials.thisN and the catch trials are still shown after each trial.
At the beginning two trials appear, then the catch trial follows and from there on the catch trials are shown after each trial.
I can’t figure out what the problem is.I use exactly the same code in a different loop and it works fine there.
Thanks for your help!

Is this code in Begin Routine? You can only use continueRoutine=False in Each Frame if you want it to work online.

The codes are in Each Frame.

After I have deleted the Coockies in my browser, the code works online. So I think the solution was to use trials.thisN.
But it works not the way I would like it to. I want the catch trial to come after every fourth trial. At the moment the catch comes at the beginning after the fifth trial, then after every fourth trial and at the end there are only 3 trials left. I have 20 trials and I want to show a chatch trial after every fourth trial.
Do you have an idea how i can adapt the code?

´if trials.thisN == 0 or trials.thisN % 4 != 0: continueRoutine = False´

Thanks!

Try
´if trials.thisN == 0 or (trials.thisN+1) % 4 != 0: continueRoutine = False´

This works perfectly! Is there a way to avoid showing a catch trial at the very end?
At the moment there is a catch trial shown at the end. After that there will be no more trials. Since I’m using the same code in another loop for a break, I would like to have no catch trial (or break) at the end.
Thank you!

´if trials.thisN == 0 or trials.thisN == 19 or (trials.thisN+1) % 4 != 0:
     continueRoutine = False´

This works perfectly! Thank you very much.

I have one more question about this. I would like the output to show whether the participants reacted to the catch words.

I have the following code in begin routine to randomize the catch words.
catchWord = random.choice(('fragen','meinen'))

JS
function random_character() { var chars = "fm"; return chars.substr( Math.floor(Math.random() * 2), 1); } if (random_character()==="f") { catchWord = "fragen"; } else { catchWord = "meinen"; }

In end routine I have added a code to store the shown word and the answer key.
thisExp.addData('catchWord', catch_key_resp.keys)

and JS
psychoJS.experiment.addData("pressedKey", catch_key_resp.keys);

psychoJS.experiment.addData("catchWord", catchWord);

In the output the answer key is stored and a catch word is stored for each trial (although it is only visible after every fourth trial). This is probably due to the structure of the loop and doesn’t bother me. The catch words that are saved together with the answer key in one line do not match the words I saw during the session.

It would be nice to know which words the participants saw and to which they reacted.

At any point you can save the value of a variable to the data file using thisExp.addData(‘VarName’,varValue)

Note that this needs an element of my code_JS to work without manual translation