Start stimuli in random location and move with arrows

I solved this. Sharing for anyone else that might be trying to do the same.

Firstly, I combined both into the same code component. Secondly, targetPos is a co-ordinate (‘string’ type in Python), so you wan’t just add or subtract from it - you need to index which part of the string you want to change. For me it was the x-position, the 0th item in the list. So I have:

Begin Routine tab:

import random
targetPos=[random.uniform(-.8,.8), 0.0]

Each Frame tab:

keys = event.getKeys()
if keys:
    if 'left' in keys:
        targetPos[0] = targetPos[0]-.01
    if 'right' in keys:
        targetPos[0] = targetPos[0]+.01
1 Like