Update variable value every n seconds

Hi everyone,

I’m very new to PsychoPy and would be very grateful for any help at this point. Using PsychoPy v3 on Mac OSX Big Sur.

Nature of the problem:
I’m trying to set up a Fitts-type task, i.e. target selection. I’d like the target to move in a straight line. The angle is a random value within a specific interval, and the breadth of the interval is experimentally manipulated. So I’ve set up a polygon to change position at every frame (t,t*dir), with dir = numpy.radians(random.randint(-amp, amp)).

What I’ve tried so far:
I’m trying to simulate a more or less erratic trajectory for the target by updating the direction while the target is moving. My second independent variable is the update frequency. I’ve introduced this code at the start of the rountine:

def update_dir():
threading.Timer(freq, update_dir).start()
dir = numpy.radians(random.randint(-amp, amp))

Not very successful, as the routine seems to be stuck in a loop … But I’m probably going about it wrong! Any help would be much appreciated.