showing images randomly from the same category
Hello everyone!
I've been using Open Sesame for a while now, so I've decided to start programming my experiment.
Firstly, I uploaded a bunch of different images which can actually be grouped into six different categories, and I expect that Open Sesame would randomly display one image from each category.
For the sake of clarity, I uploaded 5 different happy faces, which I named as happy-1, happy-2, happy-3, happy-4, and happy-5. I would expect that one of them would be randomly picked everytime I called for the happy condition to be showed.
Thus, I was thinking of coding something like that:
draw image center=1 file="[category_name[random1,5]]".
It does not work, though.
What would you suggest that I do?
I would really appreciate if you could help me
Comments
Hi @MicolG ,
I would start by adding a short
inline_scriptat the start of the trial sequence where you determine the file name based on thecategory_namevariable and a randomly selected digit between 1 and 5 (inclusive). This should be in the prepare phase.import random var.my_image_file = '{}{}'.format(var.category_name, random.randint(1, 5))And then you can use the variable
my_image_filein the script of yoursketchpad:Do you see the logic? And note that the two scripts use a different language: Python for the
inline_scriptand OpenSesame script for thesketchpadscript.-- Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you @sebastiaan , I definetely got your point.
Could you tell me what syntax should I use for OSWeb (javascript)?
Hi @MicolG ,
In JavaScript (i.e. an
inline_javascriptitem) the logic is the same, but the details of the implementation are a bit different. Specifically, there is norandint()function in JavaScript, so you need to implement it yourself.function randomInteger(minval, maxval) { return minval + Math.floor(Math.random() * (maxval - minval + 1)) } vars.my_image_file = vars.category_name + randomInteger(1, 5) console.log(vars.my_image_file)—Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you so much,
You've helped me a great deal!
MG