Counterbalanced selection

If this template helps then use it. If not then just delete and start from scratch.

OS (mac big sur):
PsychoPy version (2021.2.3):
Standard Standalone? (y) If not then what?:
What are you trying to achieve?:
I am trying to loop through a stimulus set with 6 conditions. (Condition col in the attached file.) Is there any way to randomly select from this file with the following constraints:
(1) no repeating rows
(2) when experiment is over, there will be an equal number of rows (18) from each condition
grid_test (1).xlsx (15.2 KB)

What did you try to make it work?:
I tried dividing the file into 8 files by condition and making an inner and outer loop in builder but it does not seem to be randomly selecting from the files, and there still remains the problem of overall equal sampling from each of those files.
What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.
The stimuli were all selected from a single file, even when I set nReps to 1 for each file’s (ie, for all the inner loops).
I’m thinking a code variable would help tremendously to maintain the single file (rather than breaking into 8), but I would appreciate any help/advice! Thank you!

One solution which I’ve used in a similar situation is to give each condition a conditionCode (0-7) and have a conditions list (initially set to [0,0,0,0,0,0,0,0]).

On each trial you check the the relevant condition.
e.g.

# Begin Experiment
nTrials = 0
conditions = [0,0,0,0,0,0,0,0]

# Begin Routine
if nTrials == 108:
     continueRoutine = False
     trials.finished = True
elif conditions[conditionCode] == 18:
     continueRoutine = False
else:
     conditions[conditionCode] += 1
     nTrials += 1

Ah, thank you! This seems like it should work. Where do i set the condition code?

Add a new column in the spreadsheet. If you sort your spreadsheet by condition then that will be very easy.

ok yes, that was easy!

What if I don’t want the routine to end after a condition has been sampled 18 times–I just want that condition to no longer be sampled, ie, no matter what, there should be (1) 108 trials, and (2) 18 trials from each condition.

Right now the whole experiment stops when any condition reaches 18

Please could you post the code you used?

if nTrials == 108:
    continueRoutine = false
    trials.finished = true
elif conditions[conditionsCode] == 18:
    continueRoutine = false
else:
        conditions[conditionsCode] += 1
        nTrials += 1

grid_test.xlsx (17.7 KB)

Change true to True and false to False

The experiment is crashing when you first try to run continueRoutine = false

thank you so much! works beautifully!