Blocks not randomized in pavlovia


My first Q is, to randomize the 2 routines under ret1_rand and ret2_rand. Although everything was set the same way, randomization under the ret2_rand loop was successful but ret_1rand repeats each routine twice, why?
code in Each frame (also tried in begin routine):

if nRepsImlist == 0: #in the first routine
    continueRoutine = False

if nRepsWlist == 0: #in the second routine
    continueRoutine = False

#the same is repeated for ret2_rand
if nRepsImlist2 == 0: #in the first routine
    continueRoutine = False

if nRepsWlist2 == 0: #in the second routine
    continueRoutine = False

The second Q is I wanted to randomize 2 blocks in the same way. I have 2 blocks in my study (see image). I added these blocks as loops but it did not help and I removed them and demonstrated them in the image.

In the first routine of B1, each frame:

if nRepsIm == 0:
    continueRoutine = False

In the first routine of B2, each frame:

if nRepsLan == 0:
    continueRoutine = False

I tried this by adding a loop around the each block and setting nReps as nRepsIm and nRepsLan but it did not work either. It finishes the first block, then starts the second (not successful randomization) and after the second block it repeats the first block.

I spent a few days creating random blocks of trials (successfully) however later it did not work online (a problem in the data output). I need to start collecting data soon. Your urgent help is much appreciated.

  • to randomize the blocks, I added
if nRepsLan == 0:
    continueRoutine = False

this code in every routine – each frame under Block2


if nRepsIm == 0:
    continueRoutine = False

under the every routine – each frame of Block1.
did not work either

Hi @B.D.5,
Let’s start with your first question. Could you please clarify what you are trying to achieve? You write:

Do you mean that your two loops are both set to loopType “random” but only one has random trial order with respect to the excel file? If so - does it happen only on Pavlovia or also locally? Last question - what is the code that you pasted trying to achieve?

Now your second question:

do you mean that you want to have random order of the blocks? So that sometimes block B2 is first and sometimes B1? There are two relatively easy ways to achieve this:

  1. have three blocks: B1, B2, B1, each in a loop where nReps for both B1 loops is controlled by two different variables: n_b1_first, n_b1_second for example. If you want B2, B1 order you set n_b1_first to zero and n_b1_second to 1. If you want B1, B2 then n_b1_first = 1 and n_b1_second = 0.
  2. If your B1 and B2 are identical in structure (as your screenshot suggests) - then maybe you just need one block and a few variables to control whether this block behaves as B1 or B2.

Thank you so much for the answer, as you see in the images, they all are set to random but loop in the first block is repeating itself 2 times but not in the second block.

The code is reading the excel file in the outer loop. If the relevant nReps is 0,it passes the that routine and starts with the second, if 1, it initiates the loop.

I understood your point, In my comment below, I tried to do it but I guess in the wrong way. Do you have any suggestions?

Just to make sure we are on the same page:

  • loop is used to repeat a routine or a sequence of routines (with different variables for example), not to randomize the order of these routines
  • loopType set to “random” does not specify number of repetitions, only how rows are drawn from the excel file
  • the nReps for both loops (ret1_rand and ret2_rand) in your screenshot is 1 so the excel file with the conditions should repeat once in each loop. However, the loops use different excel files, so their length may differ.

I understood your point, In my comment below, I tried to do it but I guess in the wrong way. Do you have any suggestions?

I’m still not sure what you are trying to achieve. Do you want to randomize the order of blocks or the order of trials within each block?
If you want to randomize the order of blocks, then I’ve already suggested an outline of a possible solution.

BTW, you don’t need the code that you paste in each frame of the loop - just set nReps in the loop gui to the relevant variable (for example nRepsLan).

The reason @B.D.5 is using that code is to remove excess blank lines in the data file that you get from the method of variable nReps.

1 Like

For my second Q:
I want to randomize the order of Blocks as indicated in the image. Sometimes B1 will come, sometimes B2. However, creating several inner and outer loops ended up problematic data output. That is why I wanted to randomize the blocks with a code. So, ret1 and ret2 do not matter they are just for randomizing the order of routines.

In this suggestion, I did not understand how you defined n_b1_first cause in my Control loop, the nReps are defined as nRepsIm (for block1) and nREpsLan (for block2)

Thanks for clarifying, I noticed that pavlovia does not support “is trials” loop option, but I didn’t know this is a workaround for that.

Ok, thanks for clarifying. I just have one more question to be 100% sure: do you want to randomize whether B1 OR B2 is shown, but not necessarily the order in which both B1 AND B2 are shown? I ask becasue you mention “Sometimes B1 will come, sometimes B2”, which suggests that you want to show only one of these blocks per participant.

If you want to randomize the order of block presentation, so either “first B1, then B2” or “first B2, then B1” then my suggestion was to have three blocks in following order: B1a, B2, B1b (where B1a and B1b are identical). Then if you want B1, B2 order you set variable that controls nReps of B1b to 0 (and other nReps variables - for B1a and B2 - to 1). This way B1b is not shown but B1a and B2 are, giving you B1, B2 order. On the other hand, if you want B2, B1 order you set the variable that controls nReps of B1a to 0 (and other blocks’ nReps to 1). You get B2, B1b order and because both B1a and B1b are identical, effectively the order you get is B2, B1.

There might be a more elegant solution to your problem if you B1 and B2 blocks are similar enough. For example if the only difference between B1 nad B2 is the conditions file, then you could just change the conditions file name via some variable. But this requires knowing what happens in the routines that consitute B1 block and B2 block.

Both blocks will be presented but the order will be randomized. I am a Pscyhopy novice so I am not sure if I understood you clearly. Do you mean adding custom variable in the first routines of the blocks? I never tried adding variables. Could you please describe more?

B1 and B2 are very similar, I copied B1 and created B2 as a second block and change a few things (e.g. cond file, scale points of the slider).

In general - yes. But the specifics depend on on how you want to control the ordering of the blocks. If you want it to be chosen randomly, once for the whole experiment, then you could add a code component to the first routine you have (the code component can be fund under Custom components). Then in the code component you’d have to choose “js” in the CodeType (as far as I know automatic python->js translation does not handle generating random values well, but I may be wrong). In the textbox under “Begin Experiment” you can then write:

randval = Math.random()

if (randval < 0.5) {
  n_rep_b1a = 1;
  n_rep_b1b = 0;
} else {
  n_rep_b1a = 0;
  n_rep_b1b = 1;

(this code was not tested and I don’t program in javascript so it may not work or at least be suboptimal!)
Then in your loops that control whether given block is presented you would put in the nReps field:

  • for B1a block loop: n_rep_b1a
  • for B1b block loop: n_rep_b1b
1 Like