It looks like you're new here. If you want to get involved, click one of these buttons!
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?
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: http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.get
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: http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.set
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):
Your experimental overview should look something like this:
Does that make sense?
Lotje van der Linden - http://www.cogsci.nl
Great! It perfectly works. Thanks a lot.
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?
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.
My problem was not an access problem. I forgot to give "my_duration" a starting value as you mentioned...
Thanks again for your help!
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:
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!
There's much bigger issues in the world, I know. But I first have to take care of the world I know.
thank you very much, it perfectly works as I wanted with this strategy.