Terminating the experiment

Hello,

I have a simple experiment that works well but I can’t make it quit when ‘space’ is pressed which is not a correct answer. Correct answer is to press ‘right’. The code I use is below. I tried adding core.quit() thing to Each Frame part but it didn’t work. The experiment keeps on continuing to proceed until the end. Any suggestions would be great.

Here is my conditions file:

Begin experiment:
sayac = 0

End routine:
if key_resp.corr:
sayac = sayac + CorrPoint
elif not key_resp.corr:
trials_2.finished=True
continueRoutine = False

I think the problem is that your code is in the End Routine tab - this runs when the Routine is already ended. If you move the code to Each Frame then this should end the Routine

Thank you @TParsons When I moved the code to Each Frame it doesn’t even begin the task. Do I need to have another code in the End Routine tab? What else should I do?

Does it give you any error when it doesn’t run?

No, it doesn’t give any error. Actually, it runs the instructions and also shows the sample practices but skip the main trials which are Beads_80_20 and Beads_60_40 for the experiment.

Could you share the .psyexp file for your experiment? I’m interested to see what the trials_2 and trials_4 loops are doing - it may be ended them as soon as they begin

Sure, thank you!

JTC.psyexp (56.0 KB)

Ahh I see what’s happening - when you set a correct answer, key_resp.corr is False until the correct answer is pressed. So saying if not key_resp.corr: is not “if they give a wrong answer”, it’s “if they haven’t given a correct answer (yet)”, so it ends immediately.

What you need to do is put the whole thing inside of:

if key_resp.keys:

That way it only checks the status of .corr after something has been pressed

Thank you! I just noticed that my keyboard name and the name of the keyboard in the code does not match. Now they match and works with .corr :robot: