I wanna randomly select five stimuli among the total(45)

Hi all~
My experiment is cognitive bias modification.
My experiment has two blocks.
One is preliminary with five stimuli and the other is main trial with 45 stimuli
So I wanna randomly select five stimuli for preliminary among the total(45 stimuli).
And, of course, the total is used in the main trial.
then, what should i do?
This is my builder, and preliminary


and this is main trial

I didn’t know how to do it, so I made two Excel files seperately.
And, in the preliminary trial file, I just selected five stimuli one by one each time by generating random numbers on the Excel.
But it’s soooo uncomfortable :cry:
Help me please.

Each repetition of the loop, Psychopy will add 1 to the variable thisTrial, so to choose 5 trials at random and then end the loop you just have to create a Code component with this in the “End Routine” tab:

if thisTrial >= 5:
    break

break is a command in Python which ends the loop it’s in - and code from this tab is put within the trial loop, so that’s the loop it will break. So this code is essentially saying “after 5 trials, end the trial loop”

thank you sooomuchTParsons :joy:
but yet i can’t understand …
i put '44 stimuli(now 44 are total.) ’ used in main trial in condition
and I check ‘is trial’ and I put 1 in nResp $
like this


is it right?

and… i create a code component with in the “End Routine” tab in trial loop



but there was an error.
image
What did i do wrong?

You’re getting that error because pretrials is the name of the loop itself, not the number of the trial you’re on. The loop itself doesn’t have a numeric value, so when you ask Python “is this greater than 5?” it doesn’t know how to answer (it’s like asking “is a chair less than or greater than 5?”). You need to compare it to thisTrial, or pretrials.thisTrialN, as this will be a number. The rest looks fine though!

wow TParsons thank you very much
i solved it :rofl: :innocent: :innocent: :innocent:
Have a happy day :innocent:

sorry
TParsons
I have another problem.
I have to syn on pavlovia with changed experiment for online experiment
but The Pavlovia link is suddenly not working with the code you mentioned.

Oh, and since i did it the way you did it, there were six stimuli, so I modified it like this.


What should I do?
In Pavlovia, It keeps popping up like this.
image
What’s the problem?