How to play randomly just one of the variables (picture or movie) in the routine?

Hello everyone,
I’ve create an experiment with a routine and a loop. The routine has four stimulus (text, sound, picture, and movie), All of them are variables (text, sound, pic, and ges). They also were defined in a loop condition. The sequence of the routine is as following picture.

First, the word and its spelling are played simultaneously. After that, I want to play randomly picture or movie (not playing both of them). Is it possible that only one of these variables (picture or movie) are played in the routine?

Best wishes

Hi,
I read my topic title again, It is better to write:
How to play randomly just one of the stimuli (picture or movie) in the routine.

Insert a code component from the “Custom” component tab. In its “Begin experiment” tab, put:

# import a function to allow you to get a random selection
# from a list:
from numpy.random import choice  

In the “begin routine” tab, put something like:

# select a stimulus type for this trial, from two equiprobable options:
chosen_stimulus = choice(['picture', 'movie'])

# record the selection in the data file:
thisExp.addData('chosen_stimulus', chosen_stimulus)

Then in your pic and ges components, you could try something like this in the start field, set to be controlled by a “condition”, rather than a start time or frame number:

t >= 4.0 and chosen_stimulus == 'picture'

or:

t >= 4.0 and chosen_stimulus == 'movie'

as appropriate.

For improved timing performance, you might also want to use a “Static period” component to allow your stimuli to be loaded before they are set to appear, as you have a period during the start of your trial when nothing else is happening…

Thanks Michael,
I will do it according to your recommendation. After that, i report it.
I hope I can.
Best
Kazem

Hello Michael, I insert a code component regarding to your recommendation, but there is a error. Please see these pictures:
It is my experiment:point_down:

These are code component :point_down:

and this is a error :point_down:

would you please help me?
Best
Kazem

Sorry, I was missing some square brackets in the call to choice() (which indicates that the function should choose elements from a specified list). Have amended the original post, but for clarity, that line should read:

chosen_stimulus = choice(['picture', 'movie'])

No problem. I corrected the code component and added these square brackets. After that, I ran the experiment. This time, The first and second stimulus (text and sound_1) run correctly but the new error is appeared. It is the error :point_down:

I send the properties of pic and ges. Maybe I create them falsely.


I don’t know where the problem is?

You have the “start” field set to time (s) but it should be set to condition, as mentioned originally.

i.e. we are setting a logical condition that must be met for the stimulus to be displayed. This is a series of expressions (t >= 4.0 and chosen_stimulus == 'picture') that evaluates to either True or False, not a simple time in seconds.

Thanks for the clear and comprehensive screenshot sequences, they make it very easy to give assistance. :+1:

PS note that each of the constants in those expressions (i.e. currently 'pictures' and 'gestures') need to exactly match the respective options in the line of code that was this, unless you have changed it:

chosen_stimulus = choice(['picture', 'movie'])

You can use whatever values you want, just make sure they match between that line of code and the two expressions in your start fields.

Oh no, you are right. I forgot to change time to condition.
You are welcome, indeed I help myself by sending screenshot, because in this way you help me better. By the way, thank you.
I changed the expressions according to code. Finally I ran the experiment, but just two stimulus were played (one picture and one movie), while the loop condition had 9 conditions. Look at this picture please :point_down:


Is there any relation between nReps $ in loop properties and this event? I set it to 1, because there is not need to repeat the trial, but all of the conditions must be played.

You are right, you only need an nReps value of 1 to get 9 trials.

I suspect that the issue is simply that there is no specified end condition for the trial. If there is no specified end for the stimuli, or there is no other way specified to end the trial (e.g. by pressing a key), then the trial will continue indefinitely. For example, you can specify a duration for your picture stimulus (say 1 second), which will count down from the time that the stimulus start condition is met. I think that movie and sound stimuli don’t need a specified duration, as Builder can I think tell when they have finished playing, but stimuli like text and images will definitely need some specified end point if they aren’t to be displayed indefinitely.

Once all the components in the routine have reached their end point, then the next iteration of the loop will start.

I think it is more complicate. I set the time duration for all stimulus, (except movie), you can see this in the privious pictures. Even for movie, I checked the ‘force end of routine’ tick. Indeed, I ran the expriment with this check and without it. The experiment did not work correctly.
Please help me if you have another idea.
I appreciate you for being respondant, Michael.

Can you post your .psyexp and conditions files here to examine?

Yes of course. it is a .psyexe
test.psyexp (11.8 KB)

and condition file
test_condition.xlsx (8.2 KB)