I’ve been working off of this tutorial to create an n-back with randomized stimuli in the PsychoPy builder with custom code; but this example doesn’t include all of the script needed.
After much trial and error and finding something approximating the missing code in this experiment, the code runs but it doesn’t actually display the randomly selected letter.
While I could just make everything based off of a fixed spreadsheet, I would rather participants did not always see the same stimuli in the same order.
I also cannot make this fully random because each participant needs to see a certain number of ‘target’ stimuli in order for scores to be comparable.
So far the python code looks like this (for a 1-back condition):
(in ‘begin experiment’)
letters = [‘B’,‘F’,‘K’,‘M’,‘Q’,‘R’,‘X’]
(in ‘begin routine’)
n = 1 # specify the n condition
letterSelected = False # a boolean to state a letter has not yet been selected
thisLetter = “0” # predefine the letter to zero based. Note that changing this does not make the stimuli appear.
if not target: # if this is not a target trial
while not letterSelected:
thisLetter = letters.slice((-1));
if len(presentedLetters1back) < n or thisLetter != presentedLetters1back[-n]:
# if n letters have not been presented or this is not the same as the nth trial back
letterSelected = True
presentedLetters1back.append(thisLetter); # add to list of presented stimuli
stimulustext_1back.setText(thisLetter); # add randomly selected letter to text component
Things I’ve tried and other settings:
- defining thisLetter with other randomization methods including Math.random().
- shuffling letters to a new variable and then selecting thisLetter as the first item from that variable
- the code component is the first component for the routine in builder view.
- the stimulustext_1back is set to “set every repeat”.
- setting the text to thisLetter.toString().
- I cannot find the accompanying files to this demo.