Shuffle with condition in pavlovia

Hi, :slight_smile:
Running experiments online in pavlovia is new to me and I have only basic knowledge about coding in python.

I am trying to push in a pavlovia stroop task with a specific kind of order stimuli - color of words should not be in the same color one after the other.
In my local computer I use code component to shuffle rows in excel file and it work:
Here is the code from begin experiment to shuffle:
import pandas as pd
import random

while 1:
choices = pd.read_excel(“blocks.xlsx”)
choices = pd.DataFrame.to_dict(choices.T)
shuffle = []
last = “”

while choices:
    remaining = choices 
    if last:
        remaining = [choices[x] for x in choices if  choices[x]['color'] != last['color'] ]
        remaining = pd.DataFrame(remaining)
        remaining = pd.DataFrame.to_dict(remaining.T)
    if not remaining:
        #no valid solution
        break 
    newElement = random.choice(list(remaining))
    last = remaining[newElement]
    shuffle.append(remaining[newElement])
    for each in choices:
        if choices[each]['index'] == remaining[newElement]['index']:
            del choices[each]
            break
if not choices:
    pd.DataFrame(shuffle).to_excel("after_shuffle.xlsx", index=False)
    break

I have a problem with pushing experiments in pavlovia. I see window with “Intilazing experiment” and then it freez. Nothing else happened…
What did you try to make it work?:
I had tried to debug it and see how it works in dev tool and in js script and I saw syntax errors when packages such as numpy append in script. I know that packages from python do not work in pavlovia. I want to ask - is it possible to do order my stimuli in this specific order - the same color of words should not repeat one after another
I couldn’t figure out how to make it work online without these packages but with this conditional order. Is it possible in another way?
Further information: I used PsychoPy Version 2021.1.2 (Builder) for programming.

Can anyone please help me? Any help will be greatly appreciated!!

Check my crib sheet to find that pd won’t work and how to define randint.

The logic behind how I approach this issue is as follows.

Make a list of the options.

If there are six options then start with thisOption=randint(0,6) a random number from 0 to 5.

For following options thisOption=(thisOption+randint(1,6))%6 which adds a random number from 1 to 5 and then takes the modulus 6 of the answer to keep it in the range 0 to 5.

Use options[thisOption]

You mean list of the options as list of word stimuli or list of combinations when my condtition is meet? I have ten words in four colors and this give me 40 stimulis . And could you tell me where I am suppose to do it? In begin expetiment or begine routine?

Are you wanting to present all 40 stimuli or just 10?

You’d could pick the first item in Begin Experiment and then the rest in Begin Routine.

My method is for random presentation of colours, and won’t easily present each word exactly once in each colour if you have 4 colours for each of 10 words.

I want to present all of 40 stimuli. In specific order - one color of stimuli after another color of stimuli. I also suggest that they shouldn’t be the same but in different colors like: blue - green - blue - yellow etc. So I want present each word exactly once in each color . Thank you I appreciate your help

If you don’t want consecutive trials to have the same colour or word then the best option might be to shuffle the list and on each trial pop the last item in the list. If it’s the same as the previous trial then add it to the start of the list .pop(0) offline