Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

how to calculate total duration time of sketchpad?


I am planning an experiment about solving an anagram.
Every time participant sees a word, he/she presses any key and write the word into the text input and then anagram comes again. I want them to be able to see anagram only for 180000 ms in total. I could calculate the time between the time_anagram and time_text_input and I could get the cumulative total. But because this calculation is based on time_text_input, when the time is up anagram doesn't disappear. It only disappears after the text_input, if the time is up.

So, I need a variable which counts the duration time of the sketchpad including anagram, independent from text_input. When cumulative total of time_anagram reaches to 180000 ms, the loop should break.

Is there any suggestion to solve this problem?

Thanks in advance!


  • Hi,

    This requires some scripting. Basically, what you need to do is to compute the residual time after every item has been executed. The time that is left, you should set then as duration/timeout field for the next item. That way you can make sure that the sequence does not last longer than 180 seconds. Depending on your experimental structure, you can build some other conditioning around that.

    Does that make sense?


  • Thanks for your reply Eduard!

    I am not sure if I got it correctly: Is this way independent from text_input phase?

    That actually makes sense, but here is the thing: suppose that participant saw the anagram (sketchpad) for 178 seconds and press the key and saw the text input and wrote the word. Then he/she saw the anagram again and it doesn't stop until he/she presses the key again. Because this script is based on the residual time between the anagram and the text input. So he/she can see the anagram for much more seconds than 180, whenever he/she presses the key again. I need a variable based on duration time of the sketchpad, not based on a subtraction script. Because this way doesn't actually standardize the duration time of the anagram for all of the participants. I need to find a variable to break the loop when time is up, even it was on the anagram phase. Is it possible?

  • Hi,

    you are right, I made a mistake. I think what you want is not possible to do with sketchpads and text_input_forms only. Maye co-routines can help you? If I am not mistaken you can set an overall duration for a co-routine, I am just not sure whether you can (and if so, how easy it is) to wrap a co-routine inside a loop.

    Regardless, it should be possible to accomplish this with some python coding though. So, use an inline_script and start a while loop. This loop lasts for 180 seconds. Further, every time an event is detected, it changes the stimulation. Once done, it continues to sample for a key press, while throughout keeping track of the time in the background. This code here is not supposed to work, but could you get started:

    <br /># canvas object replaces a sketchpad
    cv = Canvas(),0,100,color= 'red',fil=True)
    # make a custom text input form. see here:
    # check this, I didn't really try to make a reasonable form
    form = Form(
        cols=[1,1], rows=[1,2,1],
        margins=(50,100,50,100), spacing=25
    input_widget =Text_input(var=input_variable, timeout = 2)
    form.set_widget(input_widget, (0, 0), colspan=2)
    # make a keyboard item
    kb = Keyboard(timeout = 2)
    t0 =
    formFinished = 0
    while (clock.time()-t0)<  180000:
        # check whether a response is given
        if k != None:
            # show the form,
            # once the form is clicked away, log that
            formFinished= 1
            # only wait for a key response if we are in the canvas phase
            k,t  = kb.get_key()
        if formFinished:
            # if the form is over, move to the canvas phase
            k = None
            formFinished = 0

    Again, I didn't test this code and didn't even try to make it perfect. I hope you will understand the logic of how to approach this problem with python coding.

    Good luck,

Sign In or Register to comment.