OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2020.1.3
Standard Standalone? (y/n) If not then what?: yes
I was trying to build a self-paced reading task from scratch. To do so, I followed all the instructions from the thread created on the Google Forum and the older posts on this forum. I inserted the code in the required tabs to mask the sentences and collect the inter response interval (IRI) every time the subject presses the space bar. Then, I tried to run the experiment: everything worked fine, except for the collection of IRIs. In my data file, the only registere IRI value is called IRI_0, and I think it refers to the first time the space bar is pressed, at the very beginning of every loop. I created an Excel file which contains 3 cells, each of them containing one sentence, all under the same column called “sentence”. Here’s the code I inserted in the trial Routine:
*Begin Experiment Tab* # now define a function which we can use here and later on to replace letters with '-': def replaceWithdash(textList, currentWordNumber): dashSentence = '' for index, word in enumerate(textList): # cycle through the words and their index numbers if index != currentWordNumber: dashSentence = dashSentence + '-' * len(word) + '-' # add two strings of dash characters else: dashSentence = ' ' + dashSentence + word #except for current word return dashSentence # yields
*Begin Routine Tab* # remove any keypresses remaining in the buffer from # before this routine started: event.clearEvents() #this breaks your sentence's single string of characters into a list of individual #words, e.g. 'The quick brown fox.' becomes ['The', 'quick', 'brown', 'fox.'] sentenceList = sentence.split() #keep track of which word we are up to: wordNumber = -1 #-1 as we haven't started yet # now at the very beginning of the trial, we need to run this function for the # first time. As the current word number is -1, it should make all words '-'. # Use the actual name of your Builder text component here: sentences.text = replaceWithdash(sentenceList, wordNumber) # In the Builder interface, specify a "constant" value for the text content, e.g. # 'test', so it doesn't conflict with our code.
*Each Frame Tab* keypresses = event.getKeys() # returns a list of keypresses if len(keypresses) > 0: # at least one key was pushed if 'space' in keypresses: thisResponseTime = t #the current time in the trial wordNumber = wordNumber + 1 if wordNumber < len(sentenceList): if wordNumber == 0: #need to initialise a variable timeOfLastResponse = 0 #save the inter response interval for this keypress, #in variables called IRI_0, IRI_1, etc: thisExp.addData('IRI_'+str(wordNumber), thisResponseTime - timeOfLastResponse) timeOfLastResponse = thisResponseTime #update the text by masking all but current word sentences.text = replaceWithdash(sentenceList, wordNumber) else: continueRoutine = False #time to go on to the next trial elif 'escape' in keypresses: core.quit() # I think you'll need to handle quitting manually now.
Can somebody help me, please? I’m kind of stuck at this point
Thank you in advance!