[solved] Using random values in Sketchpad
Hello friendlies,
For my Bsc-thesis I'm trying to recreate an experiment using OpenSesame. It's a fairly basic experiment (I'd say), consisting of 3 different kinds of stimuli:
Ongoing Task (OT), Distractor Task (DT) and Ambiguous Task (AT). All three consist of a focus point and one digit above in case of the OT, a digit both above and below focus point in case of DT & AT. 80% of the time I'd like to present the the OT-stimuli, the other 20% is reserved for the other two. As switching between stimuli is important, I need some kind of randomness implemented. I'd expect there to be an easy way to implement such 'randomness', however, as I'm a total newbie to OpenSesame, I'm having trouble finding said way. Is this possible, without having to dive deep into the python inline?
Another randomness issue I'm having:
I found another forum post which a question related to randomness (http://forum.cogsci.nl/index.php?p=/discussion/240/solved-variable-interstimulus-interval-isi/p1) and I tried using what I could get from that in my project, where I'd like to vary both between randomly picked digits and their respective greyvalues (RGB values?).
I managed to add an inline_script element to my trial_loop, with the following piece of code (thanks to lvanderlinden):
import random
stimuli_values_set = [1,2,3,4,6,7,8,9]
use_this_number = random.choice(stimuli_values_set)
exp.set("use_this_number", use_this_number)
Then I figured, I can just call on this variable in my Sketchpad, to draw whichever number is produced by picking from that list:
draw textline 0 -192 "[use_this_number]" center=1 color=#7f7f7f font_family="mono" font_size=64 font_italic=no
But sadly, it's not working as I'd hoped (parallel to this I would love to randomize the color of the drawn digits).
Hope both of these 'questions' aren't all that 'stupid' nor overwhelming.
Thanks alot in advance.
Regards,
daan
Comments
Hi Daan,
Your approach is correct! Could it be that you have placed the code for the random number in the Run phase of an inline_script item? It should be in the Prepare phase, as this is when the sketchpad is constructed. For more info on the difference between the Run and the Prepare phase, see here.
On your other problem, of random RGB values, just extend your script a bit:
And adjust your sketchpad a bit:
Good luck!
Edwin
I love how quick you guys are with your replies! And I had been wondering what that little 'Prepare' tab was for!
Thanks a lot, should make things alot easier.
As for the 'pseudo randomness' of the different stimuli. It feels fairly simple, mainly using the GUI and just some python inline, to create something like:
Would you agree?
What feels like an extra problem though: with this randomness I might end up presenting subjects with a trial consisting of only one of two critical trials. Is that something I'd just have to live with (i.e. discard these in my results)?
Glad that helped! I'm not quite sure what your pseudocode should do, but if you are trying to implement the 80% OT, 10% DT and 10% AT design, I wouldn't go for a completely random approach. That is: it might be better to randomize the order, but to make sure that the trial occurrence percentages are in fact 80-10-10.
One way to do this, would be to create a loop with 10 cycles. In this loop, define a variable called
trialtype
, and use that variable as a Run if statement in your trial sequence. Would look something like the attached images:loop: use either the amount of repeats, or the Break if statement to stop the experiment at some point.
sequence: use the Run if statements to selectively run a single trial sequence from one of the trial types.
overview: design each of the single trial sequences any way you would want to.
EDIT
I just realized, when using your setup (as above) I could just use a different keyboard response for each trial, without them intervening with one another. So let me rephrase my question: how would the OpenSesame command 'set correct_response "a;b"' look in Python inline?
/EDIT
Thanks alot. I will use this!
Another quick question:
in one trial, responses made aren't relevant. In other words: I want to count any button press (within allowed responses) to count as correct. I can't find a way to do this..
I've been working with:
This piece of code runs in the prepare bit of an inline_script at the start of my critical_trial_loop.
Hi Daan,
As you note, you could simply use a different keyboard_response for every trial type. If you want to handle responses yourself, I would suggest using a single inline_script, placed directly after the keyboard_response:
Does that make sense?
It sure does! Looks like some things I tried, but never got the result I wanted. Guess I'm going with your approach now anyway, so doesn't really matter.
Thanks so much for your advice so far. I might need you again in the near future, will let you know
Hi Edwin,
I've progressed somewhat in designing my experiment. It works so far, save the Ambiguous Task-trial: same problem as before basically, I can't seem to get the multiple correct responses to work.
My trial for-loop:
The AT_keyboard_response looks like this:
Now, when I run a test-trial, [acc] is calculated correctly, except when an AT turns up. Somehow it won't accept any of four keypresses as correct. I've tried to implement some version of what you presented above, like so:
And that's where I'm stuck basically. Any ideas?
Found a solution somewhere on the forum, don't ask how I missed that earlier!
Thanks for helping out, you can close this one
Awesome! I'm glad you figured it out Will mark this one as solved!
By the way: rather than the multiple options as the correct response in a keyboard_response item, you could have used the inline_script approach I describe in one of my previous posts in this thread.