Emotional Stroop Task problem of randomization and valence

Hello everyone,

I am using PsychoPy for the first time and I am new to coding. I’m working on creating an Emotional Stroop Task (EST) with three valences for the words (positive, negative, and neutral), which need to be associated with three valences of images (positive, negative, and neutral), resulting in a 3x3 design with 9 conditions in total.

I’ve created 9 separate Excel files for both the word valences and the image valences. Additionally, I made an Excel file called “condition_file”, which contains two columns: one for the image condition Excel files and one for the word condition Excel files, and put it in a loop. The images loop works fine, but I’m having several troubles with the words’ files.

The issue I’m facing is that I want the words to be shown in random order while ensuring that the same colour does not repeat two times in a row (e.g., no two blue words in consecutive trials). I’ve tried multiple lines of code to solve this but nothing seems to work as expected.

In my Excel files for the words, I have a column labeled “colour” to assign each word its specific colour and a column for “correctAns” to specify the correct key associated with the word. I chose this approach to directly assign the colours in Excel so that all participants see the words in the same colours.

If anyone has any suggestions or a solution to help me randomize the words while avoiding consecutive colours being repeated, I would be grateful for your help!

Thanks in advance!

Have a look at my Emotional Stroop for Mobile online demo

I can’t remember if I use it there but the way I randomise with no repeats is to use the modulus function.

For example, if you have four colours.

thisColour = (thisColour + 1 + randint(3)) % 4

This will add a minimum of 1 and maximum of 3 to the current colour index.

thanks a lot for the reply. I downloaded your EST and as I was able to understand you put the colours directly using code, while I assigned the colours specifically to each word. You also used this lines of code:
thisColour=useColours.pop()
thisExp.addData(‘Colour’,colours[thisColour][0])
thisExp.addData(‘Answer’,colours[thisColour][1])

I don’t know if it’s easier to assign colours directly through code and then add the data on the dataset…