| Reference | Downloads | Github

Display problems

Hello everyone,

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
    #2 Display problem
    if o == "letter-number":
        self.text.setText(str(l) + str(n))
        self.text.setText(str(n) + str(l))
    #3 Determine correctresponse
    if pos == 5:
        if l in vowels:
            correctresponse = ['q']
            correctresponse = ['p']
        if n%2==0:
            correctresponse = ['q']
            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.interval_duration = 1.5
        self.interval_duration = 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?

Your line
doesn’t actually flip the window. You need

Without the brackets you merely refer to the function. With the brackets you call the function. This can be confusing, especially for matlab migrants, because in matlab you can call things without brackets if they have no arguments. Not true in most other programming languages.