psychopy.org | Reference | Downloads | Github

Assign the items of two lists to strings in my condition file

Hi.

I need to show the participants 2 sentences. The structure of the sentences is pre-defined, but the content of them should be randomized. To explain in more details, you can see my condition file below:

cond

What I want is to present each statement on the screen, but instead of A and B letters, some words from the lists below would be selected randomly (without replacement):

a = [‘bear’, ‘lion’,‘tiger’,‘fish’,‘parrot’]
b = [‘mammals’,‘birds’,‘car’,‘tool’]

I tried some methods, but none of them work properly. For example, I tried the method below, but it exactly shows what I typed on the screen:

Just one thing. I create my experiment in builder view and below is its structure:

Thank you in advance for your help.

In the text field, put something like this:

$eval(statement1)

PsychoPy can’t know that what you are wanting to display is actually code rather than literal text, so you need to use the eval() function to explicitly say that you want the string to be evaluated as code rather than just displayed literally.

Regardless, the choice() function is not the right thing to use here, as the next time it is called, the chosen option on the previous trial is still there to be chosen (i.e. it isn’t sampling without replacement). A better arrangement is to randomly shuffle each list, and then pop() from it on each iteration, to permanently remove the chosen item so it can’t be sampled again. You can probably find variations of that approach on this forum.

Lastly, note that you should be storing the options chosen on each trial, so the selection shouldn’t be happening in the text field, as you won’t know what was displayed. I’d suggest you handle this all in a code component, because what you need will actually take several lines of code on each trial.

1 Like

Thank you @Michael so much. You have always been a great help.

You know, I simplified my design here. Let me explain my actual design to see whether you can help me with that. I have 16 categories, each of which has 3 members. This is how it looks like:

category

And below is a screenshot of my condition file (simplified version; just 4 trials):

cond

My aim is to randomly assign each category and member to A and C letters with these limitations:

  1. Letter B is a nonsense word chosen from a list (such as b= [Gongs, Torts, Siops,…])
  2. The method for choosing A and C are defined in Cat_Mem column. Cat-Mem means randomly choose a category for A and one of its members for C, while Cat-NonMem means randomly choose a category for A with one of the members of a different category for C.
  3. The number of trials is the same as the number of total members (here 48). Thus, every member should be selected once and only once.

Thank you @Michael in advance for your time. I know my task is a little bit complicated.