setting experiment variables
Hi all,
I'm running into a very basic problem. I'm sure I've done this successfully in the past but I just can't figure it out this time. Getting older? I dunno ![]()
What I want to do is set the duration of a sketchpad in an inline script. So, I added an inline script on a sequence and includes the following code in the Run tab:
import random
fix_durations = range(400,1700,100)
fix1duration = random.choice(fix_durations)
exp.set('fix1dur', fix1duration)
Then on a sketchpad that comes right after I use [fix1dur] in the duration field.
When I run the experiment, I get an error that the fix1dur variable does not exist. What am I doing wrong here??
Thanks,
marios
Comments
Hey!
Looks like you're using an older version of opensesame. As for opensesame 3.0 we use var. Function in opensesame 3 to create an experimental variable in python
import randomvar.fixdurations = range(400, 1700, 100)var.fixduration1 = random.sample(var.fixduration, 1)If this doesn't work add another inline script at the very start of the
experiment.
And add this code:
var.fixduration = []Alternatively you could add this variable into the loop that way you won't need any python scripting.
Hope this helps
Vatsal
Thanks Vatsal. I'll give it a shot. But I think the problem is with the last step of setting the experiment, variable, ie., this part: exp.set('fix1dur', fix1duration)
Up to that point, everything works well. That is, if I print fix1duration I correctly get one of the values from the list. But, I can't set these values to the sketchpad duration.
Even if I delete all the code and just say exp.set('fix1dur', 200), I can't use [fix1dur] in the sketchpad duration field.
marios
Hi Marios,
Put the code in the prepare phase and you should be set
Eduard
You're right, it works! Thanks Eduard!
m
Eduard, I still can't get my head around this and why the code doesn't work in the Run phase. I can see a situation where putting the code in the Prepare phase wouldn't work for me. For example, let's say I have a mouse_response item and I want to set the duration of a sketchpad based on the response RT. I would use this code on an inline after the mouse_response item but before the sketchpad:
** fixduration = 5000 - exp.get('response_time')
exp.set('fixdur', fixduration) **
and then use [fixdur] in the duration of the sketchpad.
Obviously I cannot prepare the inline as I don't have a value for 'response time' at the start. And it wouldn't work in the run phase either! My questions then are: 1) why doesn't it work in the Run phase 2) what do I do to make this work??
Cheers,
marios
Hi,
Here a link to an explanation why this is. Basically, preparing things improves the timing of your stimuli.
Sketchpads are always created in the prepare phase. That is, they are first called before all other items' run phases are called. So, if you need to present anything that depends on participants responses, you wouldn't use sketchpads, butfeedbackitems. They are created in the run-phase ofsequence, so that you can use responses to draw onto them.Hope this makes sense.
Eduard
Ok, I get it now! Thanks!!