Instead of using the joystick to click on a stimuli, is there a way to move to the next trial if the joystick collides with a stimuli?

OS (e.g. Win10): Macbook
PsychoPy version (e.g. 1.84.x): Psychopy3
What are you trying to achieve?: If the joystick/cursor touches (no actual click) one of the PNG images on screen, the image name would be saved in the data file and the experiment would move on to the next screen.
I know this can be done using python code, but I’m not sure how to do this within the builder.

This will still require your custom Python code, but you simply put that code in a graphical Code Component dialog box, so that Builder will take care of making sure that it runs at the right time (in this case, on every screen refresh).

  • From the “Custom” section of the Component panel, click the “Code” icon to create a code component.
  • In its “Each frame” tab, put something like:
current_location = [your_joystick_name.getX, your_joystick_name.getY]

# use a list of your actual Builder stimulus component names:
for stimulus in [stimulus_1, stimulus_2, stimulus_3]: # etc
    if stimulus.contains(current_location):
        # save whatever is relevant to you:
        thisExp.addData('contacted_stimulus', stimulus.name)  # e.g. stimulus_1
        thisExp.addData('contacted_filename', stimulus.image) # e.g. cat.png
        continueRoutine = False # end trial
        break                   # stop this loop from doing further checks


1 Like