Conditional branching in experiment with a performance score counter

Hi! I am rather new to Psychopy and did some research on conditional branching and found some really helpful links/discourse. However, I still have some queries.

I have an experiment that the participants listen to sound stimuli and press a response key. I would like to create a condition in which if the participant is able to correctly answer 8 out of 12 trials in the practice loop, the participant will then move on to the test round. However, if the participant does not, they will move on to another trial round.

How can I achieve:

  1. a performance score counter in the experiment for the conditional branching
  2. a conditional branch of an example such as:
    if performancescore >= 8
    nRepsA = 0
    else
    nReps = 4
  3. both of these together in the experiment and builder view

Is the coding above correct? or is there an easier way to achieve this?

1 Like

You need an arrangement something like this:

The outer repeats loop just needs an unfeasibly large nReps value, like 100, and is not connected to a conditions file.

The instruction routine is needed so that people know when they are about to start another round of 12 trials. If you want to, you could put something like this in a text stimulus, so they can keep track of how many tries theyā€™ve had:

f'Attempt number {repeats.thisN + 1}.'

The feedback routine is so they know how they did on the last round.

In the trial routine, insert a code component and put something like this in its ā€œBegin routineā€ tab, so the score gets reset only at the start of each inner loop:

if practices.thisN == 0:
    score = 0

Then in the ā€œEnd routineā€ tab:

if your_keyboard_component_name.corr:
    score = score + 1

if score == 8:
    practices.finished = True
    repeats.finished = True

Then in the ā€œFeedbackā€ routine, put something like:

$f'You got {score} correct.'

in a text stimulusā€™ text field, set to update every repeat.

This will terminate the loops early if the participant scores 8 before the 12 trials are completed ā€“ I think this is what you want?

Iā€™m not sure what you mean by this? Regardless, all of the instructions above are purely for implementing in the Builder view.

Hi Michael,

that is a really helpful reply! However, I am still confused as to do we really need that many repetitions?

How would you propose for the below flow and how to add the elements in?

In my .xlsx file for the trial, there are a total of 12 stimulus. Therefore, what i want is that if the participant response correctly for at least an 8 out of 12 for these stimulus, they will proceed to the test round, else they will do another 4 stimulus.

I realized i could have confused you with the word ā€˜trialā€™. Trial in this instance would mean the stimulus in the routine.

I read your request as meaning that they would keep repeating blocks of 12 stimuli until they got at least 8 correct. If you only want one block of 12 stimuli, and will accept that they continue on without achieving 8 correct, then simply delete the repeats loop in the suggestion above. The practice round will still end early if they do get 8 correct.

Hi Michael,

Thanks for the reply! It is really helpful :slight_smile:

Is there another way to do this? I would like them to complete all 12 stimuli and not that they score 8 and then end early. So essentially, the scoring part comes after they have completed all 12 stimuli.

We seem to be going in circles here. If they need to complete 12 trials, no code is needed: just let the loop run to completion.

So if thatā€™s the case, now I donā€™t understand what the scoring actually does. What action will occur if the person doesnā€™t achieve at least 8 correct trials out of those 12?

Think how you might explain this in the methods section of a paper, so that the reader understands unambiguously what the procedure was.

So basically if the person doesnā€™t achieve at least 8 correct trials out of those 12, they will continue to do another 4 trials of practice. If they achieve at least 8 correct trials out of 12, they will just proceed to the test routine. Hence thatā€™s why I need the scoring to assign the participant to the extra 4 practice trial or to proceed towards the test routine

I hope this makes sense!

OK, so the loop needs 16 iterations. Amend the code in the ā€œend routineā€ tab to be something like this, so it will end on the twelfth (counting from zero) if the criterion is met, otherwise the remaining four will run:

if practices.thisN == 11 and score >= 8:
    practices.finished = True

Hi Michael,

Thanks so much for your help! This has been really helpful :slight_smile: