Recording location in trial, code component failing

I am working within the Builder view of PsychoPy, but with a code component added in.

In the test phase of my experiment, I am essentially trying to show a fixed scene image (locationScene) in the Builder view. I have 2 objects underneath with 2 polygons behind them, labelled slots. I want the slot outline behind the object to be outlined green, and the participant can click on anywhere in the scene image. Then, I want that object slot colour to return to transparent/white, and for the second object slot outline to turn green, and record a 2nd mouse click. The trial then loops.


LocationTesting.xlsx (9.3 KB)

I have the code component of this (I don’t know how to code, I have just tried my best to amend a previous code section that was successful so I am hoping this is a simple fix)
Begin routine
clicks = 0
clicked_positions =
mouse.clickReset()

clickable_positions = [locationScene]

slot1.lineColor = ‘green’
slot1.lineWidth = 4
slot2.lineColor = ‘white’
slot2.lineWidth = 1

Each frame
if clicks == 0:
if mouse.getPressed()[0]:
# record click location relative to locationScene
clicked_positions.append(mouse.getPos())

    # Change outlines: slot1 turns white, slot2 turns green
    slot1.lineColor = 'white'
    slot1.lineWidth = 4
    slot2.lineColor = 'green'
    slot2.lineWidth = 4
    
    clicks += 1
    mouse.clickReset()  # reset to avoid multiple detections this frame

elif clicks == 1:
if mouse.getPressed()[0]:
clicked_positions.append(mouse.getPos())

    clicks += 1
    mouse.clickReset()
    
    continueRoutine = False  # end trial after second click

End routine
thisExp.addData(‘clicked_1_x’, clicked_positions[0][0] if len(clicked_positions) > 0 else ‘’)
thisExp.addData(‘clicked_1_y’, clicked_positions[0][1] if len(clicked_positions) > 0 else ‘’)
thisExp.addData(‘clicked_2_x’, clicked_positions[1][0] if len(clicked_positions) > 1 else ‘’)
thisExp.addData(‘clicked_2_y’, clicked_positions[1][1] if len(clicked_positions) > 1 else ‘’)

reset slot colors if needed for next trial

slot1.lineColor = ‘white’
slot1.lineWidth = 1
slot2.lineColor = ‘white’
slot2.lineWidth = 1

Running: /Users/Nessa/Desktop/honours/PsychoPy Testing/LocationTrial (v1a)/LocationTesting_lastrun.py

2025-05-16 20:56:25.717 python[8829:4974857] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/5m/nb9x9g5s0mscmtptvb2_hdv00000gp/T/org.opensciencetools.psychopy.savedState

PsychHID-ERROR: Could not enumerate and attach to all HID devices (HIDBuildDeviceList(0,0) failed)!
PsychHID-ERROR: One reason could be that some HID devices are already exclusively claimed by some 3rd party device drivers
PsychHID-ERROR: or applications. I will now retry to only claim control of a hopefully safe subset of devices like standard
PsychHID-ERROR: keyboards, mice, gamepads and supported USB-DAQ devices and other vendor defined devices and hope this goes better…
PsychHID-INFO: That worked. A subset of regular mouse, keyboard etc. input devices and maybe some vendor defined devices will be available at least.
20.7092 WARNING Couldn’t measure a consistent frame rate!

  • Is your graphics card set to sync to vertical blank?
  • Are you running other processes on your computer?

10.0283 WARNING t of last frame was 30.19ms (=1/33)
11.3886 WARNING t of last frame was 33.22ms (=1/30)
11.4229 WARNING t of last frame was 21.37ms (=1/46)
12.9697 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
Boolean HIDBuildMultiDeviceList(const UInt32 *, const UInt32 *, int): Couldn’t open IOHIDManager.################# Experiment ended with exit code 0 [pid:8829] #################

I have uploaded a video of what typically happens when I try to run my experiment. A random blank screen occurs, and the trial doesn’t allow for 2 object clicks on each trial with the same scene.

I’d appreciate any help at all! Thanks :smile: