| Reference | Downloads | Github

Shuffling stimuli prior to trials, stimuli not found after a "rest break" routine

OS: Windows 10, version 20H2, OS build: 19042.1237
PsychoPy version 2021.2.3

Hello. I have been creating a picture naming experiment with the psychopy builder and have been using the the <\ > Code component to add functionality that is not default in builder. The flow of the experiment is as follows:

The Stim_loader includes the following custom code.

begin experiment

#Create empty lists
pnt_list = []
random_list = []

**Begin routine **

#save each word as the loop iterates

The loader_loop loads the condition file necessary for the experiment which contains 175 conditions with 2 parameters: stim_images and Block. Stim_images contains the file locations for the 175 pictures to be used in the experiment. Block can be ignored.

In the word shuffle routine i randomize the 175 images into two lists to be administered before and after the break routine. Within this routine there is one code block that I have labeled codeShuffler Within the Begin routine section I have the following code:

#Shuffle stimuli list

pnt_list1 = pnt_list[0:87]
pnt_list2 = pnt_list[87:175]

The following routines run fine after this: Main, PNT_instructions, Practice_items, end_practice, PNT_1, and Break and the error arises when I include PNT_2 in the experiment. PNT_1 and PNT_2 are formatted nearly identically. The functional PNT_1 contains, code, image, and a keyboard component. Within the code componenet I have the following:

Begin Experiment

#Item counter
curr_item = -1

Begin Routine

#increment item counter by 1
#starting at negative 1 makes python chose first item with the beload code
curr_item += 1

#update the item variables as we progress through list
word = pnt_list1[curr_item]
random = random_list[curr_item]

To call the images within the image component I input $word and “set every repeat”.

The PNT_2 routine contains identical code but with slightly different labels.
Begin Experiment

#Item counter
curr_item = -1

Begin Routine

#increment item counter by 1
#starting at negative 1 makes python chose first item with the below code
curr_item += 1

#update the item variables as we progress through list
word2 = pnt_list2[curr_item]
random = random_list[curr_item]

When I run the experiment without the PNT_2 routine it runs without errors. When I run the experiment with PNT_2 I get the following error:

Traceback (most recent call last):
  File "C:\Users\alexa\OneDrive\Documents\GitHub\PNT-CAT\AnomiaR01\PNT_beta\", line 172, in <module>
    image=word2, mask=None,

One secondary question The output file I create with this experiment does not include the stimulus name (image_PNT)**

It is not clear to me what or where I should add the code to make sure the output file also contains the stimulus name, not just the response.

Thanks in advance for any help. This is my firs ttime posting here, so apologies if I do not format totally correct!

Just wanted to bump this to see if I can provide any additional information to help solve this problem

I was able to solve this problem by shuffling the data into one continuous data set, and then adding an if statement as follows. I added a break routine within the main stimulus loop, but after the experiment block called “PNT_1”. The break routine includes a text component that simply states “Break” in the middle of the screen and it remains on this screen until the user hits space bar. The keyboard command was included by having a key response below the text component, with the only acceptable response of “space.”

The guts of making a break within a random set of stimuli comes by adding a code component. This was pretty easy, but I just wasnt aware of the “this.N” command. Of note, i collapsed all stimuli into the pnt_trials loop, which now contains all the stimuli and a break occurs are the first half of the items (87) has been delivered.

So within the “each frame” block of the custom code componenet I wrote

if pnt_trials.thisN != 87:
continueRoutine = False