URL of experiment: Sign in · GitLab
Description of the problem: Hello everyone!
I have built an experiment in the Builder and attached a code component to some routines. The experiment is a moving window self-paced reading task.
Although it runs smoothly when I run it on PsychoPy, I’ve been facing some issues while trying to run it online.
Since I don’t know much (anything at all, actually) about programming languages, I talked to a developer who translated the codes of the code component so I could start from somewhere. We’ve been trying to get it to run online for the past days, and yet, nothing works.
I honestly have no clue what to do next. If anyone can shed some light, I’d be very thankful for anything, really!
There are basically 2 code in the components (that repeat on some other routines, changing the text component they associate with as well as the column in the xlsx file).
The begin routine:
Python
sentenceTREINOList = sentenceTREINO.split(‘/’)
#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.’]#keep track of which word we are up to:
wordNumber = -1 # -1 as we haven’t started yet#now define a function which we can use here and later on to replace letters with ‘x’:
def replaceWithX(textList, currentWordNumber):
xSentenceTREINO = '' for index, word in enumerate(textList): # cycle through the words and their index numbers if index != currentWordNumber: xSentenceTREINO = xSentenceTREINO + '_' * len(word) + ' ' # add a string of x characters else: xSentenceTREINO = xSentenceTREINO + word + ' ' # except for the current word return xSentenceTREINO # yields the manipulated sentence
JavaScript:
var setenceTREINOlist = sentenceTREINO.split(‘/’);
var wordNumber = -1;
function replaceWithX(textList,current){
var xSetenceTREINO = ‘’;
var index = 0;
for(word in Object.values(textList)){if(index != currentWordNumber){ xSetenceTREINO = '_' * word.length + ' '; }else{ xSentenceTREINO = xSentenceTREINO + word + ' '; } index = index+1; } return xSentenceTREINO;
}
And the each frame:
Python
#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 ‘x’.
#Use the actual name of your Builder text component here:text_10.text = replaceWithX(sentenceTREINOList, wordNumber)
#In the Builder interface, specify a “constant” value for the text content, e.g.
#‘test’, so it doesn’t conflict with our code.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(sentenceTREINOList): 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_TREINO_' + str(wordNumber), thisResponseTime - timeOfLastResponse) timeOfLastResponse = thisResponseTime # update the text by masking all but the current word text_10.text = replaceWithX(sentenceTREINOList, 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.
JavaScript:
text_10.text = replaceWithX(sentenceTREINOList, wordNumber)
var keypresses= event.getKeys();
if (keypresses.lenght > 0){
if(keypresses.include('space')){ thisResponseTime = t ; wordNumber = wordNumber + 1; if (wordNumber < sentenceTREINOList.lenght){ if (wordNumber == 0){ timeOfLastResponse = 0; } thisExp.addData('IRI_TREINO_' + str(wordNumber), thisResponseTime - timeOfLastResponse) timeOfLastResponse = thisResponseTime; text_10.text= replaceWithX(sentenceTREINOList, wordNumber) } else{ continueRoutine = False } } else if (keypresses.include('escape')){ core.quit(); }
}