I am trying to modify an already well running experiment in psycopy builder. The purpose is to save time by not running the rest of the trials after two inaccurate responses.
As you can see it has got three loops; ‘trials_2’, ‘trials’, and ‘trials_4’. Each loop has its own condition file.
A condition file has about 10 trials (10 rows). A column of a condition file contains ‘corrAns’. I would like the program to not run the remaining of the trials(rows), if two consecutive responses by the participant are inaccurate. My code component at the moment looks like this.
I had started the counter by stating ‘score=0’ at Begin Experiment of the code component.
##################
if mouse_10.isPressedIn(image_20):
continueRoutine = False # trial will run again
thisExp.addData('repeat', 'yes')
else :
thisExp.addData('repeat', 'no')
for stimulus in [image_21, image_24]:
# check if the mouse is pressed within the current one:
if mouse_10.isPressedIn(stimulus):
# Yes, so store the reaction time in the data:
thisExp.addData('RT', t)
# check if the stimulus' image filename matches the correct answer:
if stimulus.image == eval(corrAns):
thisExp.addData('score', 1)
score = score + 1
else:
thisExp.addData('score', 0)
# end the trial once done here:
continueRoutine = False
trials_5.finished = True
break
I think this can be dome pretty easily but I have little success with my tries so far.
I think the easiest way would be to count the incorrect answers in your else condition:
wrongAnswer = 0 #set this at the start unless you only want the trial to end after 2 consecutive incorrect answers.
# check if the stimulus' image filename matches the correct answer:
if stimulus.image == eval(corrAns):
thisExp.addData('score', 1)
score = score + 1
else:
thisExp.addData('score', 0)
wrongAnswer +=1
if wrongAnswer == 2:
trials_5.finished = True
I tried doing this. But it seems to do nothing. I have little idea as to where the ‘wrongAnswer=0’ goes. For the moment I have put it at the top of the ‘Each Frame’.
continueRoutine = False
trials_5.finished = True# ends the inner loop
if wrongAnswer==2:
trials_3.finished=True# i hope this shoud end the outer loop.
break
Hi - for += 1 to work there needs to be a variable set for it to be added to. Putting this at the beginning of the routine would work if you only want two incorrect answers to occur. Having it at the top of every frame means that it will never = 2 since it gets reset every frame.
Hi Oli
Thanks. It works now, however,i just realized it ends ths loop when the ‘wrongAnswer=2’, what I would need is, I want it to end the loop when TWO SUCCESSIVE answers are wrong (not the sum of wrong answers is 2). Is it possible to do it?
My code component at the moment looks like this
Begin experiment:
wrongAnswer = 0
Each Frame:
if mouse_10.isPressedIn(image_20):
continueRoutine = False # trial will run again
thisExp.addData(‘repeat’, ‘yes’)
else :
thisExp.addData(‘repeat’, ‘no’)
for stimulus in [image_21, image_24]:
# check if the mouse is pressed within the current one:
if mouse_10.isPressedIn(stimulus):
# Yes, so store the reaction time in the data:
thisExp.addData('RT', t)
# check if the stimulus' image filename matches the correct answer:
if stimulus.image == eval(corrAns):
thisExp.addData('score', 1)
score = score + 1
else:
thisExp.addData('wrongAnswer', 1)
wrongAnswer= wrongAnswer + 1
# end the trial once done here:
continueRoutine = False
trials_5.finished = True
if wrongAnswer==2:
trials_2.finished=True
break
Dear Oli
Here is another problem, quite similar to the earlier one. So I thought this thread will be a good one.
I have two separate loops with their own condition files. On the first condition file (for the first loop of course), the two columns that has the stimuli looks like this
I want the first loop to end (not playing the further trials), if the responses to both the trials within an item are incorrect. At the moment I just have a counter for ‘score’, under begin experiment of code component
score=0
My each frame looks like this
for stimulus in [image_3,image_4]:
# check if the mouse is pressed within the current one:
if mouse_3.isPressedIn(stimulus):
# Yes, so store the reaction time in the data:
# check if the stimulus' image filename matches the correct answer:
if stimulus.image == eval(corrAns):
thisExp.addData('score', 1)
score = score + 1
else:
thisExp.addData('score', 0)
# end the trial once done here:
continueRoutine = False
# stop any further checking:
break