Howdy, Stranger!

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

Supported by

[solved] vary a sketchpad duration according to the previous response time

edited July 2013 in OpenSesame

I want a sketchpad duration to vary according to a previous RT. Setting the duration '2000-[response_time]' does not work it seems because "-" is not recognized as an operator. How can I do this?


  • edited 12:52PM


    The 'duration' box in a sketchpad item only takes fixed variables. As a solution, you can calculate the desired duration in an inline_script item placed immediately before your sketchpad item. Next, you can use the square-bracket method (e.g. [my_duration]) in the duration box.

    You can calculate the desired duration by placing something like the following code in the Prepare phase tab of your inline script:

    # Set the maximum:
    max = 2000.
    # Determine the RT on the previous trial by 
    # using the experiment function self.get().
    # See:
    dur = max - self.get("response_time")
    # Set the resulting duration so that the variable becomes
    # available in the interface (i.e. in your case a sketchpad item)
    # as well:
    # See:
    exp.set("my_duration", dur)

    This code will work on all trials except the first trial of your experiment, because at that time the variable 'response_time' does not have a value yet. Therefore, you should also append a second inline_script item to the very beginning of your experiment, and give 'response_time' a starting value. You can do this by placing something like this in the Prepare phase tab:

    # Give the variable 'response_time' a starting
    # value such that it already exists for the very first 
    # trial (otherwise OpenSesame will give an error
    # saying that the variable 'response_time' does
    # not exist):
    exp.set("response_time", 0)

    Your experimental overview should look something like this:


    Does that make sense?

    Best wishes,


  • edited 12:52PM

    Great! It perfectly works. Thanks a lot.

  • edited 12:52PM


    I just realized that with your help I collect the rt of the previous trial, but I would like to collect the rt of the current one.
    I tried several things but coulnd not find any solution for the moment. Would you have any idea, please?

  • edited 12:52PM

    I found the beginning of a solution.
    When I use your code in the "Run Phase" and I display response_time in the debug window, my_duration displays the correct current RT.

    My last remaining problem is that, now, I cannot access to the variable "my_duration" on another sketchpad (placed after the inline of course). I tried to declare it as "global" but that does not work.

  • edited 12:52PM

    My problem was not an access problem. I forgot to give "my_duration" a starting value as you mentioned...
    Thanks again for your help!

  • edited 12:52PM


    I'm not sure whether you already worked it out, but here's a small tip anyway. You can 'pad' the remaining time after a response with this simple script:

    total_time = 5000 # The response time + the padding time
    padding_time = total_time - self.get('response_time')
    if padding_time > 0:

    So let's say that you have sketchpad1, followed by a keyboard_response, and then you want to 'pad' the remaining 5 seconds while showing sketchpad2. You can do this with the following sequence:

    • sketchpad1 (duration = 0)
    • keyboard_response
    • sketchpad2 (duration = 0)
    • inline_script (with the code show above)

    Does that make sense? So you don't use the 'duration' parameter of the sketchpad, but simply use an inline_script item.

    Hope this helps!


  • edited 12:52PM

    thank you very much, it perfectly works as I wanted with this strategy.

Sign In or Register to comment.