psychopy.org | Reference | Downloads | Github

Defining stimuli within a loop

OS Win 7
PsychoPy version 3.0.4
Standard Standalone? Y

What are you trying to achieve?:
I am trying to properly define my stimuli in the excel sheet used in a loop:

I am replicating Frank’s probabilistic learning task. The task uses 3 pairs of stimuli:
Pair 1: A & B
Pair 2: C & D
Pair 3: E & F
Each stimuli (A:F) is randomly assigned a character from the Hiragana alphabet. They must all be different.

During the procedure, each pair is presented 20 times. Participants have to pick one of the Hiragana characters. Character A will give them extra points if picked over B 80% of the time, character C if picked over D will give extra points 70% of the time and character E if picked over F will give extra points 60% of the time.

There are two main steps that I need to take:

  • define each stimulus (A:F) with a unique Hiragana character (this will be random and different for each participant)
  • create pairs of stimuli with adequate feedback for each pair

What did you try to make it work?:
I have split the Hiragana alphabet into 6 files, in each file there are different characters. I have added a code component with a loop for each stimulus (letterA:F) which randomly assigns a Hiragana character to each stimulus (example below):

letterChoice1 = data.TrialHandler(nReps=1, method='random', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('hiragana1.xlsx'),
    seed=None, name='letterChoice1')
    
thisExp.addLoop(letterChoice1)  # add the loop to the experiment
thisletterChoice1 = letterChoice1.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisletterChoice.rgb)
if thisletterChoice1 != None:
    for paramName in thisletterChoice1:
        exec('{} = thisletterChoice1[paramName]'.format(paramName))

for thisletterChoice1 in letterChoice1:
    currentLoop = letterChoice1
    # abbreviate parameter names if possible (e.g. rgb = thisletterChoice.rgb)
    if thisletterChoice1 != None:
        for paramName in thisletterChoice1:
            exec('{} = thisletterChoice1[paramName]'.format(paramName))

letterA = letters1 #letters1 is the name of the column with the characters

I did the loop 6 times and this way I have assigned a Hiragana character to each of the six stimuli (letterA:F). I used these to create my 3 pairs of stimuli.

Example of the characters:

I have made an excel file where I have specified the pairs and adequate answers required for each of the stimuli pair.

The routine includes two text fields that are being shown simultaneously (a stimuli pair).
I will also add a response component there.

What specifically went wrong when you tried that?:
The first (minor problem) is is that the Hiragana characters do not show up, there are Latin letters on the screen instead. It is ok, I can change these to jpg images at a later stage.

It seems like both of my solutions worked fine but separately.

  • define each stimulus (A:F) with a unique Hiragana character
  • create pairs of stimuli with adequate feedback for each pair

When I tried to put $letterA or $letterB in the text components, randomly picked Latin characters were being shown in pairs. However, this was limited only to the A&B pair and I needed to have trials of all pairs presented randomly throughout the block.

When I added the excel file, and changed the text component to $letter1 and $letter2 it seemed that my arrangement of the stimuli pairs worked. There were now different pairs being shown randomly throughout the block.

BUT The defined stimuli (random latin letters) were not shown. Instead, it was the actual values presented in the excel file (e.g. letterA, letterB etc…).

How can I mark my randomly defined stimuli in the excel sheet so that it correctly displays the latin letter pairs?

All help will be VERY appreciated !!!