Hi, I new to programming and I am trying to code my very first experiment.
The problem I am having is that I don’t know how to “link” the correct response (keyboard “left” and “right”) to the images (arrows pointing to the left or to the right).
With the code that I wrote (please see below) it seems that random correct responses are being linked to the pictures. How could I fix this? Thanks in advance
code:
from psychopy.visual import Window, ImageStim, TextStim
from psychopy.core import wait
from psychopy import gui, visual, core, data, event, logging, clock
from psychopy.event import waitKeys
import random
# Create a window
disp = Window (size = (1440, 900), units="pix", fullscr=True)
#Target locations
TARLOCS = ["upcongLeft","upcongRight","upincongLeft","upincongRight"]
#Potential targets
TARGETS = ["left","right"]
#Potential SOAs
SOAS = [0.1,0.9]
#Fixation time at the start of a trial
FIXTIME = 1.5
#Duration of the cue Screen
CUETIME = 0.1
#Duration of the feedback Screen
FEEDBACKTIME = 1
# number of times to repeat training mode
TRAININGREPEATS = 1
#All possible target stimulli
tarstim = {}
tarstim ["upcongLeft"]= ImageStim(disp, size=(300,300), image="upcongLeft.png")
tarstim ["upcongRight"]= ImageStim(disp, size=(300,300), image="upcongRight.png")
tarstim ["upincongLeft"]= ImageStim(disp, size=(300,300), image="upincongLeft.png")
tarstim ["upincongRight"] = ImageStim(disp, size=(300,300), image="upincongRight.png")
#Draw incorrect Feedback
fbstim = {}
fbstim[0] = TextStim (disp, text="Incorrect!", height=24,\
color = (1, -1, -1))
#Draw correct Feedback
fbstim[1] = TextStim (disp, text="Correct!", height=24,\
color = (-1, 1, -1))
# Create an empty list to contain the training trial
training = []
# Loop
for cueside in CUELOCS:
for tarside in TARLOCS:
for soa in SOAS:
for tar in TARGETS:
# Training dictionary
trialtraining = {"cueside":cueside, "tarside":tarside,\
"target":tar, "soa":soa}
# add the trial dictionary to the list
training.extend (TRAININGREPEATS * [trialtraining])
# Randomise
random.shuffle (training)
# Loop
for trialtraining in training:
# Draw a target stimullus
tarstim[trialtraining ["tarside"]].draw()
# Update the monitor
taronset = disp.flip()
# Wait for a response
resplist = waitKeys (maxWait=float("inf"), keyList = ["left", "right"],\
timeStamped = True)
# Select the first response from the response list
response, presstime = resplist[0]
# Check if the response was correct
if response == trialtraining ["target"]:
correct = 1
else:
correct = 0
# Show feedback
fbstim[correct].draw()
disp.flip()
wait (FEEDBACKTIME)
disp.close ()