Manipulating routine order

Hello there, this is my first post, and my first fumbling attempt at making an experiment in PsychoPy. I’ve read a book that introduced me to Builder, and I am familiar with writing some basic code in Python, but now that I am programming my own experiment, I find that I need to know a lot more about how the code works. So before I get on to my real question, if anyone has suggestions for how to get acquainted with code that goes with making experiments - tutorials, youtube clips, walkthroughs, books - I’d be happy to hear them.

Now for my question. I have six different trial types (or rather, routines), and I would like to be able control how the experiment progresses from one trial (routine) to the next. For now I am only managing to play them in sequence. To make this easier to imagine, it is a paradigm where three players, two of which are digital, toss a ball to each other. Each toss is a routine, because I need a loop of images to run from a conditions file, forming a movie sequence.

For some trials, the choice of the next trial should be automatic and probabilistic, but for others it should depend on the response given. When the player is the experimental participant, they can choose whether to toss left or right. When it is one of the other players, they also toss to one of the other players based on a random choice.

In both cases, there should be an event at the end of the trial, either a response (‘left’ or ‘right’) or a random choice (again ‘left’ or 'right) which determines which player gets the ball next - i.e. which trial should play next. But how do I tell PsychoPy to go to this routine? I can imagine having something like ‘player 2’ and telling it to ‘go to player 2’, but how is this done?

You might find the workshop materials helpful for this! Building better experiments — Workshops for PsychoPy 2020 2020

Thanks, Becca! These do look very useful.

In the meantime I have made some progress, but am stuck again. I think I have the right idea of how to select a routine on each loop, but for some reason my select row variable is not updating. Help please?

I’ve created a smaller version of the experiment where either Text A or Text B should flash on the screen. After each instance of a text flashing, I want python to randomly select which of the two should flash next. So within the trial, after the text, I put in this code:

# End Routine
options = ['left', 'right']
x = np.random.choice([0,1])
choice = options[x]

if choice == 'left':
    NextRow = '0' # A
if choice == 'right':
    NextRow = '1' # B

(I’ve put ‘left’ and ‘right’ because later on some of these will be arrow key responses instead of random choices, but I run into the same problem if I try to use the output of key_resp.keys)

Then in an outer loop, I have a conditions file that has different rows for playing A or B:

nRepsA nRepsB
1 0
0 1

What I want is the Selected Rows box of the outer loop to update with the value of $NextRow, but that seems not to be happening. If I run five loops, text A will flash five times and that’s it. I think if I solve this problem I should be able to figure out the more complicated version of the experiment I described in the first post.

I’m attaching the relevant files.

conditions_AorB.xlsx (8.2 KB)
cybertry_mini3.psyexp (13.7 KB)

Hi There,

I don’t think you would need a code component for this even! if you have 2 routines (one that shows A where the loop around is has nRepsA in the Reps field, and a second that shows B and has nReps B in the Reps field, then put a bigger loop around both of them where your conditions file is fed in - if that outer loop has it’s loop type set to “random” then it will be random if routine A or B is presented next!

Hope that helps,
Becca

Hi Becca,

The thing is, I don’t want it to be random in reality, it’s just that this play version of the experiment looks like that. In the final experiment there will be six routines, where routines A, B, C and D should have two possibilities following (a random choice between two of the remaining five routines), while routines E and F should have two non-random possibilities following based on a response. In other words, my question really is how to select the routine that follows based on code I input in the current routine.

(Later on, I will also want to add a non-equal distribution between the two choices… it will get much more involved.)