URL of experiment: https://gitlab.pavlovia.org/jenny.retzler/memory_span
My experiment runs fine in builder and has some code components. I think it is my poor attempts at translating these to JS that is causing the error ‘failed to parse as JS by esprima’. The files upload to Pavlovia but the study gets stuck at the ‘initializing experiment’ screen. I suspect the problem is in the ‘Each frame’ block of the code associated with one routine and may relate to mouse.getPressedIn, but despite finding some relevant threads and looking at examples such as the Corsi blocks, I’ve been unable to solve the issue.
Begin routine (Python):
pracCount=pracCount+1
squares=[RSq1,RSq2,RSq3,RSq4,RSq5,RSq6,RSq7,RSq8,RSq9,RSq10,RSq11,RSq12,RSq13,RSq14,RSq15,RSq16]
clickSequence=[]
clickedSquare =[]
clickedSquareNum =[]
Begin routine (attempted JS equivalent):
pracCount=pracCount+1;
squares=[RSq1,RSq2,RSq3,RSq4,RSq5,RSq6,RSq7,RSq8,RSq9,RSq10,RSq11,RSq12,RSq13,RSq14,RSq15,RSq16];
clickSequence=[];
clickedSquare =[];
clickedSquareNum =[];
Each frame (Python):
for square in [RSq1,RSq2,RSq3,RSq4,RSq5,RSq6,RSq7,RSq8,RSq9,RSq10,RSq11,RSq12,RSq13,RSq14,RSq15,RSq16]:
if mouse.isPressedIn(square):
#find out the square name
clickedSquare = square.name
#extract the number only from the square name
clickedSquareNum = int(''.join(filter(str.isdigit, clickedSquare)))
#avoid double-clicks and add to clickSequence
if clickSequence==[]:
clickSequence.append(clickedSquareNum)
elif clickedSquareNum!=clickSequence[-1]:
clickSequence.append(clickedSquareNum)
# all clicked?
if len(clickSequence) >= len(respSequence):
continueRoutine = False
event.clearEvents()
Each frame (attempted JS equivalent):
if (mouse.isPressedIn(square)){
clickedSquare = square.name;
clickedSquareNum = clickedSquare.replace(/[^0-9]/g,@'');
if (clickSequence===[]){
clickSequence.append(clickedSquareNum);
}
else if (clickedSquareNum!==clickSequence[-1]){
clickSequence.append(clickedSquareNum);
}
}
}
if (clickSequence.length >= respSequence.length){
continueRoutine = false;
}
End routine (Python):
thisExp.addData('clickSequence',clickSequence)
#determine if all items recalled, order doesn't matter
if list(set(clickSequence))==list(set(respSequence)):
correctCount=correctCount+1
End routine (attempted JS equivalent):
psychoJS.experiment.addData('clickSequence',clickSequence)
if (clickSequence.length === respSequence.length && clickSequence.sort().every(function(value, index) { return value === respSequence.sort()[index]})=true){
correctCount=correctCount+1;
}
There are one or two other very basic code components I can provide info for if needed, but I think it is unlikely that they are the issue.
Thanks in advance for any help - sorry for the long post!
Jenny