How to correctly set up a random loop and a sequential loop

In my experiment, subjects were shown three videos in a random order. Before each video was played, I created a separate routine and told the subjects the instructions in the form of pictures: please adjust your sitting position, I will watch the 1st 1/2/3 video, press the space to continue and so on. My workflow is as follows.


I’ve created a conditional document for randomly displaying videos and set it to a random loop, and it works fine. But I want the image instruction in front of the video to play sequently instead of randomly, and now I don’t know where to put the condition file for the image. Here are my specific Settings.


I think setting up a random loop and a sequential loop at the same time bothers me. How do I solve it in builder? Or do I need a code? However, I don’t know the syntax of python, but I appreciate any help.

Hello

I do not yet have a clear understanding of your work flow.

  • You want instruction 1 to appear before all randomly played three videos, then instruction 2 and randomly play your three videos aso.? So, instruction 1, random video 1 - video 3; instruction 2, random video 1- video 3 aso.?
  • or instruction 1, then randomly 1 out of 3 video; instruction 2, then randomly 1 our 2 videos; instruction 3 last video?

Best wishes Jens

Hello Jens

I’m sorry I didn’t describe it clearly.

According to your description, the working mode I need to implement is the latter, that is, instruction 1+ video B (for example), then instruction 2+ video A, instruction 3+ video C. I want to determine the order in which the instruction pictures appear, but the order in which the videos appear after that is random.

You can see a method of how to do this in my Independent Randomisation demo

Hello

Thanks to your response, I ran the Independent Randomisation file and found that it allowed 26 letters and 10 numbers to appear completely randomly on the left and right sides of the screen. However, in my experiment, I want the number variable to be sequential, such as 0,1,2,3… 10, and the order of the letters is random, such as G, F, Z, and so on. I want to show the numbers first and then the letters, so it’s best to split them into two routines.

Please forgive me for using this forum casually as a beginner psychopy, if it is just because I do not understand the code in the sample file, please tell me how to operate or modify it.

Best wishes Kenukiri

The key is that in the demo one set of values gets preloaded into a list and the second is presented by the loop as normal.

1 Like

Hello

Thank you for your reply, I think I understand the meaning of the code, which helps me a lot, thank you!

Best wishes

Hello

@wakecarter was faster :wink:

Here is a toy experiment that preloads the instructions and then presents each instruction before the critical stimulus. I use text stimuli instead of pictures and videos to keep it simple.

instrucStim.xlsx (9.9 KB)
randSeq.psyexp (16.6 KB)
trialStims.xlsx (9.9 KB)

Best wishes Jens

1 Like

Hello Jens

Thank you very much for your reply, I ran your experimental program (as well as his@wakecarter), and now I understand that I need to add a piece of code that prereads a column in the table, and set this loop to “sequential” in advance.

I have now applied them all to my workflow, however, when I replace the stimulus with a picture, the program tells me
ValueError: invalid literal for int() with base 10: ‘Trial1Instruction.png’.

I think it should be that when one of the columns in the condition file is not simply text but a path, I should change the code in the sample file you provided me. I’m one step away from successfully running it :smiling_face_with_tear:

Best wishes

Hello Kenukiri

Well, if you specified the full path to the image, it should work. But the error message gives a hint.
There are several reasons why you might get such an error in Python

  • Non-numeric characters in the input string
  • Incorrectly formatted strings
  • Leading or trailing spaces

So you should try to address these reasons. Start by searching and replacing spaces in your condition file.

Best wishes Jens

Hello Jens

I tried it all day, and finally reworked the experiment file and copied the code you provided exactly, making the program work successfully.

Although I still don’t know what the problem is, maybe I made a mistake when writing the code, but now it is solved. Thanks for your advice and help! :grinning: