psychopy.org | Reference | Downloads | Github

Adjust the orientation of the bar by keyboard

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

Win10 (e.g. Win10):
**PsychoPy version: ** : 2021.1.4
**Standard Standalone? (y/n): ** YES
What are you trying to achieve?:
Firstly, participants should try to remember the orientation of a bar. After that, they should try to reproduce the angle of the remembered bar by pressing the keyboard. When pressing the right arrow, the bar should rotate clockwise, when pressing the left arrow the bar should rotate anti-clockwise. participants adjust the orientation of the bar until they think its orientation is almost the same with that of the remembered bar, and participants press enter to end this trial.

What did you try to make it work?:
I defined a variable “barorientation” as the orientation of the bar, and use the code:

the following is my routine:

What specifically went wrong when you tried that?:
the bar only rotated for the first press and ended the trial.
untitled.psyexp (12.9 KB)
many thanks if you could help me. I have been puzzled for three days. Looking forward to guidance.

Hi There,

You are close! (maybe you have figured the solution now?) What I suspect you need is in the “begin experiment” tab:

barorientation = 0

Then in the “Each frame” tab:

if res_key.keys == 'right':
    barorientation += 10
elif res_key.keys == 'left':
    barorientation -=10
elif res_keys == 'space':#Assuming you might want to submit the answer with a space?
    continueeRoutine = False

Then use barorientation in the orientation field of your stimulus.

I think you have the right code - just possibly in different tabs!

Hope this helps,
Becca

Hi Becca,
Thanks for your suggestion and help. I tried to change my code’s tab as you suggested. But it did not work.

I added the continueRoutine = Ture to the code in the tab of “each frame”, but the outcome is not what I need:
it turn out that once I press the left or right, the bar would rotate endlessly clockwise or anticlockwise, until I press the space.

but what I need is once I press the left or right, the bar only rotate for 10 degrees, and the bat would not disapear until I press the space.

I upload my adjusted program with the excel file, with both of which you can run the psychopy program.

I am looking forward to your help
thanks in advance

untitled.psyexp (13.3 KB)
file.xlsx (9.9 KB)

Hi There,

Ah I see - try this: untitled.psyexp (16.2 KB)
Becca

Wow, thank you very much!
Your program suits my experiment requirement definitely. I see you add a loop for the bar. That works well! Thank you again!

Fab! if that worked please can you mark the solution so that future users can easily find it?

Thanks!
Becca