I’m fairly new to PsychoPy and Python coding, but all my projects have gone reasonably well. My latest attempt at an experiment has got me completely puzzled though. Basically I’m trying to create a simple experiment in which 1) a fixation cross is shown (for 1.5 seconds, but 5 seconds when the answer is incorrect), 2) a problem is shown, 3) the computer waits for a response during an interval of 5 seconds from the start of the display, 4) it is determined whether the user’s response was correct and displays the corresponding feedback. I don’t think it’s particularly useful to explain what the exact problem is, but any cognitive psychologists among us might recognise it. This is what the code looks like:
def runTrial(self, t, n, l, o, pos): #1 Inter-trial stimulus self.fix.draw() self.win.flip() core.wait(self.interval_duration) self.win.flip() #2 Display problem if o == "letter-number": self.text.setText(str(l) + str(n)) else: self.text.setText(str(n) + str(l)) self.text.setPos([0,pos]) self.top_square.draw() self.bottom_square.draw() self.text.draw() self.win.flip timer.reset() #3 Determine correctresponse if pos == 5: if l in vowels: correctresponse = ['q'] else: correctresponse = ['p'] else: if n%2==0: correctresponse = ['q'] else: correctresponse = ['p'] #3 Register response response = event.waitKeys(keyList=['q', 'p'], maxWait = 5) self.RT = timer.getTime()*1000 #4 Determine if right or wrong if response == correctresponse: self.correct.draw() self.win.flip() self.interval_duration = 1.5 else: self.errors+=1 self.wrong.draw() self.win.flip() self.interval_duration = 5 core.wait(1) self.win.flip() core.wait(.5)
This code does not work. When I remove anything from the event.waitKeys() onwards, it shows the fixation cross and problem just fine. When I add the event, things start getting messy: first a fixation cross shows, then a blank screen, which lasts until I press one of the allowed keys, whereafter the problem is finally displayed for a second or so before jumping back to the fixation cross. It is almost like the waitKeys() event occurs before the problem display. I just can’t figure out what’s wrong. Can anyone help me?