| Reference | Downloads | Github

How to move stimuli receiving the key

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

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:

Hello, I’m trying to make image named ‘person’ move according to the key I give.
For example, image would move right if I press the ‘right’ key in key_resp_3.
However, my current key doesn’t work(The image literally doesn’t move.)

I have put $[x,0] in the position argument of image ‘person’,
and in code component, x=-0.5 in begin experiment tab, and following code as shown in the following screenshot in begin routine tab.

This is my current workflow

This is what I have put in Begin Routine tab of pavinst routine.

Thanks for all in advance.

What did you try to make it work?:

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

There are a few potential issues here:

  • your animation code is in the “begin routine” tab. This means that it will run only once, before the stimuli have even been drawn. You need to shift it to the “each frame” tab so that the code is run on every screen refresh during the trial, which will allow for continuous animation.
  • make sure that the position field of your stimulus is set to update on the same schedule (i.e. on every frame).
  • the initial value of x = 0.5 needs to be set in the “begin routine” tab so that it gets reset at the start of every trial, rather than once per session.
  • key_resp_3.keys returns a list of keys (hence the plural), even if only one key has been pushed. So your checks here will always fail, as a list object is not equal to a single value, even if that list contains that value. So change your check to look like this:
if 'right' in key_resp_3.keys: # etc

PS When posting next time, could you delete the unused boilerplate text?