| Reference | Downloads | Github

Yes or No options

Hello everyone,

I hope everyone is doing great. I built one of the executive functions with PsychoPy (2-back) and I would like to put an option for repeating the instruction and the practice part. So I am planning to have an option for something like, ‘Would you like to repeat the instruction/practice?’, ‘press Y for yes and N for no’. So, if they press N it will take them directly to the trails and if Y it will take the, back again to the practice/instructions part.

Please, it is urgent and I have been trying to figure it out for a while now… Maybe I am doing something wrong … I will waiting for HELP… :confounded:

1 Like

It would be helpful if you posted a minimal sample of your code to see what you’ve been doing so far and why it hasn’t been working.

One way to accomplish this would be to do a while loop:

practiceDone = False
while not practiceDone:
    # Do your instructions here
    # Do your practice trials here
    doneQuestion = visual.TextStim(win, text='Would you like to repeat the instruction/practice? Y / N')
    response = event.waitKeys(keyList=['y', 'n'])
    if 'n' in respnse:
        practiceDone = True
1 Like

Thank you so much for this great help. However, I am not sure where to input this code. in which tab of the code component do I enter this? and how do I the refer to this in the routine/loop? Sorry for I am a beginner :slight_smile:

No problem. Where you add this depends on whether you are doing this in the “Coder” interface or the “Builder” interface, and then on how you are currently doing your practice trials. It would help if you could upload your script or experiment file (usually something like name.psyexp).

I am sorry for the delay replay but I am so packed up these days preparing for my data collection :sweat_smile:. I am using the builder interface and I was trying to know where I can possibly upload my file here so you can have a look at it but still could not figure out where to do that:disappointed_relieved:. and is there a way where I can have a direct contact with you because I really need help with this matter :cry: … Thank you so much

Hi, you can attach files right here by clicking the “Upload” button when drafting a reply.

Hi - you would have a loop around the instructions, practice and option blocks with a repetitions value of $nReps - in the options block you would have a code component as well as your rating scale with yes and no as options. In the start of experiment tab have a line saying nReps=1 and in the end of routine tab have the following:

if ratingScale.getRating() == 'Yes'
     nReps = 1

Not at a computer so can’t test it - this is the general idea though so have a play.


1 Like

there is something I must be doing WRONG :cry: not working.

Hi Mada - tried this and it works fine - Good luck!

Hello Oli,

Thank you so much for your patience and great help :grin: I think the loop and the code is alright but I guess there is something wrong with my scale rating. Because I keep having this error :

rating = visual.RatingScale(win=win, name=‘rating’, marker=u’triangle’, size=1.0, pos=[0.0, -0.4], low=no, high=yes, labels=[u’’], scale=u’’)
NameError: name ‘no’ is not defined

What do you think?

and I forgot to mention, I put my code and scale rating at the end block [Inst_End] in which they will see the question which give them an option … So did I do it right?

That code is based on your psyexp file in which you use a keyboard rather than a rating scale - if you just add it to your existing file it will work.

Hi Mada,

Have you put the code in the code component, changed the number of repetitions in repeat inst to $nReps etc?

Yes, I put the code in the code component and put it at the Inst_End block . Plus, I put $nReps in my repeatinst properties and the allowed keys for the Instr_End are ‘y’,‘n’. :disappointed_relieved:

OK - so the next question is are there any error messages - why don’t you upload what you have so far and I’ll take a look.

OK - a different approach:

Set nReps in your repeatinst loop to something ridiculous like 999.

Then in your end of routine code component tab have:

if key_resp_2.keys == 'n':
    repeatinst.finished = True

The same will work for practice too - just have a repeatPractice loop.

That SHOULD work.

All the best,


1 Like

WoW now we have the repeat amazing :grin:… but now it repeats even when I click n for no?!:hushed:

Have you replaced ‘y’ with ‘n’ in your if statement?

at End Routine

if key_resp_instr_end.keys == 'n':
    repeatinst.finished = True

Begin Experiment

nReps = 1