1

I want to create an experiment in PsychoPy Builder that conditionally shows a second routine to participants based on their keyboard response.

In the task, I have a loop that first goes through a routine where participants have three options to respond ('left','right','down') and only if they select 'left', regardless of the correct answer, should they see a second routine that asks a follow-up question to respond to. The loop should then restart with routine 1 each time.

I've tried using bits of code in the "begin experiment" section as such:

if response.key=='left':
    continueRoutine=True
elif response.key!='left':
    continueRoutine=False

But here I get an error saying response.key is not defined.

Michael MacAskill
  • 2,411
  • 1
  • 16
  • 28
Natalia L
  • 43
  • 4

1 Answers1

0

Assuming your keyboard component is actually called response, the attribute you are looking for is called response.keys. It is pluralised as it returns a list rather than a single value. This is because it is capable of storing multiple keypresses. Even if you only specify a single response, it will still be returned as a list containing just that single response (e.g. ['left'] rather than 'left'). So you either need to extract just one element from that list (e.g. response.keys[0]) and test against that, or use a construction like if 'left' in response.keys to check inside the list.

Secondly, you don't need to have a check that assigns True to continueRoutine, as it defaults to being True at the beginning of a routine. So it is only setting it to False that results in any action. So you could simply do something like this:

if not 'left' in response.keys:
    continueRoutine = False

Lastly, for PsychoPy-specific questions, you might get better support via the dedicated forum at https://discourse.psychopy.org as it allows for more to-and-fro discussion than the single question/answer structure here at SO.

Michael MacAskill
  • 2,411
  • 1
  • 16
  • 28