Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

from with display block

JulietteJuliette Posts: 18
edited February 28 in Expyriment

I intended to represent 3 stimuli at the same time in each trial on the screen. In the next step, we will ask from participant to choose between one of two options and select the most relevant words to the target. In each trial, stimuli display on the screen for 6 sec and within this 6 sec participant has to answer the question and then we go to next trial. The code is as below: ( I removed not important lines)

    ## display each stimuli
    def disply_block(stim1,stim2,stim3):
        canvas = expyriment.stimuli.Canvas(size=(600, 600)) 
        stim2.present(clear=False, update=False)
        button, rt = exp.keyboard.wait(keys=response_keys,duration=6000)_

    block = design.Block()
    ## initialize experiment
    exp = expyriment.design.Experiment(name="task")
    # Define and preload standard stimuli
    blank = stimuli.BlankScreen()

    # left and right arrow keys for responses
    response_keys = [misc.constants.K_LEFT, misc.constants.K_RIGHT]
    # display triangle stimulus for  block cf
    block_one= expyriment.design.Block(name="block1")

    #trial 1
    trial1, stim1,stim2,stim3=draw_stimuli(trials['Trial0'][0],trials['Trial0'][1],trials['Trial0'][2])
    trial2, stim4,stim5,stim6=draw_stimuli(trials['Trial1'][0],trials['Trial2'][1],trials['Trial2'][2])


I have few question regarding this code and I would appreciate if you provide me a solution: it seems each trial display for 12 sec instead of 6 sec. It seems it is relevant to this part of code:

button, rt = exp.keyboard.wait(keys=response_keys,duration=6000)

Question1: how can I give the time to the participant to answer the question only within that 6 sec that stimuli display on the screen?
Question 2: how can record exact response time?
Question2: how can I be sure that only first attempt of the participant to answer the question will be recorded?
Question3: how can I be sure that even if the participant answer after 6 sec, no response will be recorded anymore?
Question4: as my participants are French speaker, how can I initialize experiment ( cut down timer/ read) in French?

Your help is highly appreciated in advance.


  • fladdfladd Posts: 69


    1. delete exp.clock.wait(6000)
      If you want to show the stimulus always 6000ms, irrespective of whether the participant answered earlier, just wait the remaining time after the exp.keyboard.wait line: exp.clock.wait(6000-rt)
    2. why would rt not be exact?
    3. see 1
    4. see 1; if the participants answers after 6000ms, then your code proceeds (e.g. shows next trial)
    5. you cannot. the countdown is only meant for the researcher, to signal that the Python core needs 10 seconds in the beginning to stabilize, in order to be timing accurate

    I hope that helped. Let me know if you have any further questions.

    Thanked by 1Juliette

    Florian Krause (Developer)

  • JulietteJuliette Posts: 18
    edited February 28

    Hi Flad, thank you very much for your informative reply. After I changed it as below:

            button, rt = exp.keyboard.wait(keys=response_keys,duration=6000)

    I got this error:

                    TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

    I try to understand what this error means.

    It's always a pleasure to exchange with you. Thank you very much and I appreciate your comments.

  • fladdfladd Posts: 69

    Oh sorry, I forgot the case that the participant does not respond within 6000ms. In this case the return value is None, None.

    So the correct code should be:

    button, rt = exp.keyboard.wait(keys=response_keys,duration=6000)
    if rt is not None:
    Thanked by 1Juliette

    Florian Krause (Developer)

  • JulietteJuliette Posts: 18

    Thank you very much. The problem is fully solved.

  • fladdfladd Posts: 69

    To explain the error message a bit: It means that you were trying to use the - operator on two things that were of different types. The 6000 is an integer, while the rt apparently was None, which is an instance of the NoneType. Python does not know how to use the - operator on these two items (as subtraction is only defined on two numerical types), and it hence threw the error you say. But with the code in my last reply this should not happen anymore, as exp.clock.wait(6000-rt) will only be called when rt is not None (which it only is when no button has been pressed; if a button has been pressed it will be an integer, that can be subtracted from the 6000ms without an error). I hope this explanation clarifies things a bit more.

    Thanked by 1Juliette

    Florian Krause (Developer)

  • JulietteJuliette Posts: 18

    Thank you. Your explanations are very clear to me. I appreciate your favor to explain it fully.

Sign In or Register to comment.