Adding custom code to ensure participant holds cursor over image for a specified time before ending routine

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): Latest
Standard Standalone? (y/n) If not then what?:
**What are you trying to achieve?: To prevent participants shooting for a target with the joystick I want to add a specific time they need to hold the cursor over a target.

The task involves participants moving an image(cursor) with th joystick to different targets. I have initially successfully managed to ensure the routine ends when the joystick is held over an image with the following code.

When I add t=3 to this it moves to the next routine when 3 secs past from start of routine not when participant is holding over target for 3 seconds. I have therefore tried the following code:

The following error apperas;

Traceback (most recent call last):
File “C:\Users\wickw\Documents\PhD\Research planning\motor task\motor task 24.11\study_task_Day1\Study_Task_1_lastrun.py”, line 1170, in
if inTarget(3):
TypeError: ‘bool’ object is not callable

Experiment ended.

I have also tried to start a new clock when the cursor enters the image and reset it if it leaves. If the clock reaches 3 secs end routine but this gives no error message but does not work.

Any help with this will be appreciated.

Regards Dave

Hello,

it is better to copy&paste code surrounded by triple ` than to post screenshots. Anyway, inTarget is a boolean-variable taking only True or False, correct?

So what do you intend to achieve with the code-lines 14-15 do?

if inTarget(3):
    continueroutine = False

shouldn’t it be

if inTarget:
    continueRoutine = False

In addition, there is a typo. It is

    continueRoutine = False

not

    continueroutine = False

Best wishes Jens

Hi Jens

Thank you for your response I have managed to solve this today. Below is the code I have used.

In begin routine
‘"TargetTimer = core.Clock()’’’
‘’‘inTarget = False’’’
‘’‘outTarget = True’’’

In every frame
‘’‘current_location = [joystick_studytrial.getX(),
joystick_studytrial.getY()]’’’
‘’‘stimulus = image_sequencetarget’’

‘’‘if stimulus.contains(current_location) and not inTarget:
TargetTimer.reset()
inTarget = True
outTarget = False’’’

‘’‘if not stimulus.contains(current_location) and inTarget:
inTarget = False
outTarget = True’’’

‘’‘if inTarget:
if TargetTimer.getTime() > 1:
continueRoutine = False’’’

Cheers Dave

Hello Dave,

cool. BTW it is triple , not triple '. See the difference in formatting of your code and my code. And you don't have to surround each line of code with triple , just one triple at the beginning and one triple at the end each in an extra row with no code.

Best wishes Jens