#### Welcome!

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

# Nested loops

Posts: 18

Hi there,

Just a quick question about nested loops in OpenSesame. We are currently creating an experiment divided in two parts: the first part is considered as an induction phase where we want to display a prime picture before each trial (same picture for every trials randomly selected from a list of 350 pictures). Then, we have the actual experiment (in a different loop) where participants can either have the same picture as in the induction phase or a different one for each trial.
For now, I combined two loops: the first loop consists of the actual trial list and the second loop consists of the pictures list (350) and by changing the "set repeat" to 0.003 I can randomly select a different prime picture for each trial.

So I can easily program the experiment so that a different picture is selected for each trial but I'm struggling to randomly select one picture that will be used both for the induction and test phases. Any hints ?

Many thanks in advance for the help !

Best,

CL

• Posts: 2,890

Ok, let me clarify the paradigm first, because it's kind of complicated:

• You have a priming experiment, in which a picture (the prime) is followed by a target stimulus.
• During the induction phase, the prime is always the same picture. This picture is randomly selected for each participant from a pool of 350 pictures.
• During the testing phase, the prime is:

• Sometimes (50%?) the same picture as used during the induction phase; and
• Sometimes (50%?) another picture, randomly drawn from the pool of 349 remaining pictures.

Is that correct?

Cheers,
Sebastiaan

There's much bigger issues in the world, I know. But I first have to take care of the world I know.
cogsci.nl/smathot

• Posts: 18

Yes, this is correct. Except that this is a between subject manipulation (same or different primes for the testing phase; 2 experiment files).

For half the participants, the picture chosen for the testing phase is the same as the induction phase (2 different loops).

For the other half of the participants, the picture for the induction phase is always the same (randomly selected) and for the testing phase, it's a new one for each trial (randomly selected)

Does this make things clearer ?

CL.

• Posts: 2,890

Hi,

So I can easily program the experiment so that a different picture is selected for each trial but I'm struggling to randomly select one picture that will be used both for the induction and test phases. Any hints

Right—so the only thing you're struggling with is randomly selecting an image during one `loop` (induction phase), and then keeping that same image for the next `loop` (testing phase)? If that's it, then it's really simple: Don't redefine the prime during the second loop!

Once you've define a variable (`prime`, say), it will persist until you explicitly delete it (which is rare) or give it another value. So if you don't add a `prime` column to the second loop, then `prime` will keep having the value that it had at the end of the first `loop`. Does that make sense?

Cheers,
Sebastiaan

There's much bigger issues in the world, I know. But I first have to take care of the world I know.
cogsci.nl/smathot

• Posts: 18

Hi there,

Thanks for the answer ! I'm struggling to select the same image for the whole loop and then sticking to it for the second one. Here is how I select a random prime for each trial:

I have three levels in my experiment (3 levels for the induction phase and 3 levels for the testing phase)

_ TrialLoop (with the list of every trials & variables)
- FaceLoop (with the list of 350 faces, with a repetition set at 0.003 to get only one new face per trial in the TrialList)
- Trial sequence: defining the trial structure (fixation, prime, response)

I'm not sure how to get the "Prime" variable to be the same image for all trials of the induction phase (I didn't work when I manipulated the 'set repeat' parameter). Once I'll manage to do that, I guess I understand what you mean by "not redifining the prime for the second loop". But, as I'm stucked at the first step, this is hard to test

So sorry, I'm sure this is an obvious manipulation but I cannot make it work !

Thanks for the help

• Posts: 2,890

Could you attach the experiment file? That will make it a bit easier to talk about.

There's much bigger issues in the world, I know. But I first have to take care of the world I know.
cogsci.nl/smathot

• Posts: 18

Hi there,

Sorry for the delay ! Here is the file. Some things might be a bit messy, any hints for improvement are always welcome

• Posts: 1,043

Hi Cletess,

I see two solutions for your problem.

1. Don't select the random image from the `loop_table` but from a `list` in an `inline_script`. Do it once before you enter the prime phase.
``````import random
no_faces = 100 # not sure how many different faces you have
faces = []
for i in range(no_faces):
faces.append('face_'+str(i)+'.JPG')

selected_face = random.choice(faces)
``````
1. First thing you do in the `loop` is creating a new image variable that you will use henceforth. In every other `loop`, you skip over this initial defining of that variable.
``````if trial_no == 1:
real_image = selected_image
# after the first iteration the variable real_image won't change anymore
# note, trial_no is not a default variable name in Opensesame, you'll have to compute it for your experiment
``````

I prefer the first one, but both should do the trick.

Hope this helps,

Eduard

Thanked by 1cletess
• Posts: 18

Thanks a lot for this ! I'll give it a go and come back at you !

• Posts: 18

Worked like a charm ! Thank you !