Does it do that on every trial? I was hoping it would count up to 3
Yeah it does it on every trial
I just noticed. You have respcorrs=[] in Begin Routine so you only get the latest score. Move that to Begin Experiment
Fantastic! It counts up then finishes after 3 correct!
I’ve just tried it in Pavlovia and it displays the message like Accuracy only 1,0,0 - then if you get two right it goes 1,1,0 three right 1,1,1 but it doesn’t end the routine after the first three being correct
I did the translation of pop(0)
Is that from textComponent.text='Accuracy only '+str(respcorrs) ?
respcorrsSum shouldn’t be 1,0,0
Check that respcorrsSum is working locally and online.
You could ditch accuracy = float(respcorrsSum)/considerNrTrials in favour of
accuracy = sum(respcorrs) if you make minAccuracy to be a min score rather than a proportion.
It is working locally and providing a sum in the text and then ending the routine after 3 correct, but it is displaying 1,0,0 online and not ending the routine.
How do I check if that element is working online?
I would ideally like to keep with accuracy as we are trying to control participant ability rather than number of trials completed (don’t really want a situation where one participant could get 30 all correct and another could get 30 correct and 30 incorrect and both progress to experimental trials)
By number correct I meant the score over the most recent 30 trials, not the total score.
If you are getting a number locally and a list online, then sum(respcorrs) isn’t behaving correctly. Did you set sum = (arr) => arr.reduce((a,b)=>a+b) in Begin Experiment of code_JS ?
Yes I think that’s what it’s doing locally, it said 1 , 2 then ended the routine on the 3rd one correct.
I have copied
sum = (arr) => arr.reduce((a,b)=>a+b)
into the begin experiment of the code_JS
Please could you show your JS code for the routine? I’m wondering whether something is happening to sum.
respcorrs.append(resp.corr);
if ((respcorrs.length > considerNrTrials)) {
respcorrs.shift(0);
}
respcorrsSum = [respcorrs].reduce( function(x,y) { return x+y; }
);
accuracy = (Number.parseFloat(respcorrsSum) / considerNrTrials);
if ((accuracy > minAccuracy)) {
continueRoutine = false;
trials.finished = true;
}
if ((accuracy > minAccuracy)) {
textComponent.text = "Accuracy reached!";
accuracyReached = 1;
} else {
textComponent.text = ("Accuracy only " + respcorrsSum.toString());
accuracyReached = 0;
}
sum is being translated by the AutoTranslate instead of by code_JS.
Just in case the auto translate is wrong (and there does seem to be an issue here) try
respcorrsSum = sum(respcorrs)+0
This will fox the auto translate and leave the JS as sum(respcorrs)+0
Great! So I changed it to the below code and now on Pavlovia the text sums up to 2, but then it stops and the routine doesn’t end at 3. Thank you so much for all your help with this.
respcorrs.append(resp.corr);
if ((respcorrs.length > considerNrTrials)) {
respcorrs.pop(0);
}
respcorrsSum = (sum(respcorrs) + 0);
accuracy = (Number.parseFloat(respcorrsSum) / considerNrTrials);
if ((accuracy > minAccuracy)) {
continueRoutine = false;
trials.finished = true;
}
if ((accuracy > minAccuracy)) {
textComponent.text = "Accuracy reached!";
accuracyReached = 1;
} else {
textComponent.text = ("Accuracy only " + respcorrsSum.toString());
accuracyReached = 0;
}
You need to put trials.finished=True back in.
It is in there, but does it need to be at the bottom?
Any ideas as to why the trials.finished=true isn’t ending the routine in Pavlovia?
This code is in End Routine, isn’t it? If so, then continueRoutine=false is inappropriate, and may also block access to trials.finished=true. You also had two identical conditional statements. Try:
respcorrs.append(resp.corr);
if ((respcorrs.length > considerNrTrials)) {
respcorrs.pop(0);
}
respcorrsSum = (sum(respcorrs) + 0);
accuracy = (Number.parseFloat(respcorrsSum) / considerNrTrials);
if ((accuracy > minAccuracy)) {
textComponent.text = "Accuracy reached!";
accuracyReached = 1;
trials.finished = true;
} else {
textComponent.text = ("Accuracy only " + accuracy.toString());
accuracyReached = 0;
}
Amazing! Thank you so much! The routine now ends.
I tried without the text component (as I don’t want this actually displaying to participants) and increasing the number of min trials to test it in full and it doesn’t always end at 30, once it ended after 26 and another after 25. Is there something happening with the code meaning it is not always reaching a minimum of 30 trials? Or do I need the code with the text function in order for the routine to end properly?
Thank you so much though, just to get to this stage I am chuffed, I appreciate all your help more than you know!
To clarify, this is the code tried to get rid of the text component:
respcorrs.append(resp.corr);
if ((respcorrs.length > considerNrTrials)) {
respcorrs.pop(0);
}
respcorrsSum = (sum(respcorrs) + 0);
accuracy = (Number.parseFloat(respcorrsSum) / considerNrTrials);
if ((accuracy > minAccuracy)) {
trials.finished = true;
}
if (((accuracy > minAccuracy) && (trials.thisN > minNrPractice))) {
trials.finished = true;
}
With that code, it ended after 30 correct but 32 trials in total. Whereas it should have ended at 30 as it would have been over 80%. accuracy
Seems to be summing correct responses, not just total number of responses. I tried changing respcorrs.length to just resp.length, but it still didn’t end after 30 trials completed (meeting 80% accuracy). Sorry to pester, but being so close to a solution I’d love to get it fully working!! Thank you again