Continue loop only if participant presses a certain key

OS (e.g. Win10 Home):
PsychoPy version 2020.2.10:
Standard Standalone? (n) II think I installed Python and then Psychopy as an additional package?:
What are you trying to achieve?:
Hi :slight_smile:
I would like to construct an experiment in which a person hears two sounds. Afterwards they can chose if they either want to listen to the sounds again or continue to the next page (where they evaluate how similar the chords are). It is very similar to what this person was doing: Getting Started — PsychoPy v2021.1

What did you try to make it work?:
I got to the point that the two sounds repeat each time ‘y’ is pressed by using a loop. I entered a code component into the routine that contains sound 1 (“C_major__triad_close_root_sinus”). In the tab “End routine” I wrote:

if ‘y’ in trial_a_repetition.keys:
repeat_trial_a.finished = True

I also tried:

if ‘y’ in repetition_trial_a.keys:
continueRoutine = False

What specifically went wrong when you tried that?:
The experiment runs until the first sound is played and then breaks.
The message is:
Generating PsychoPy script…

Running: C: …

16185.1717 INFO Loaded monitor calibration from [‘2021_01_17 18:18’]
pygame 1.9.6
Hello from the pygame community. Contribute - pygame wiki
1.4355 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).
6.0833 WARNING User requested fullscreen with size [1280 720], but screen is actually [1920, 1080]. Using actual size
Traceback (most recent call last):
File “C:\ …”, line 468, in
if ‘y’ in repetition_trial_a.keys:
NameError: name ‘repetition_trial_a’ is not defined

Experiment ended.

Do I really have to define repetition_trial_a and if so, how can I do that?

I would be very happy about any advice! :slight_smile:

repetition_trial_a appears to be the name of your routine (according to your flow) but you are using it in code as if it’s the name of a keyboard component.

It can’t be both. You need to use different names for your loops, routines, components and variables.

Thank you very much wakecarter! :blush:
I didn’t realize you had to enter the name of the keyboard component into the code!

Afterwards it still didn’t work with the continueRoutine = False command

but it worked with
if ‘y’ in trial_a_repetition_resp.keys:
repeat_trial_a.finished = True

Also I had to enter the code component into the routine called “repetition_trial_a” and not in the one that contains the first sound.

Now my experiment works which is great news for me and my boss :grin:

Have a great day! :slightly_smiling_face: :upside_down_face: :slightly_smiling_face: :upside_down_face:

1 Like