Ending the experiment when participants do not agree to participate

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2020.1.3
Hi. I put an informed consent as a text at the beginning of my experiment and ask participants to click: “I consent, begin the study” or “I do not consent, I do not wish to participate” by the mouse. I want to write code if participants select the second option, a message like “Thank you” shows and the experiment end. I tried this code in the end experiment but it does not work.
if mouse.isPressedIn(text_notconsent):
msg = ‘Thank you’
ContinueExperiment=False

I would be appreciated if you can help me with it.

As far as I understand it you are checking whether they consented at the end of the experiment. I think you should be checking at the end of the routine.

Hi @wakecarter,

Thank you for your response. I put the informed consent at the beginning of the experiment. I put the code in tab end routine but it doesn’t work.

I’ve not heard of continueExperiment

I’m on my phone but if you check my crib sheet you’ll fine core.quit() and the JS translation

Thanks @wakecarter,

I put core.quit() in my code and it works. I want to ask another question: How can I show a message before quit the experiment when ‘I do not consent’ will be clicked?

Cheers,
Mohammad

I’m stilling experimenting with how to customise the quit message. I got it working locally but it went back to “The user pressed Escape” online.

You could have a routine with a duration of 0 if consent has been given and 2 or 3 seconds when consent isn’t given and put the core quit in that routine (end Routine if duration > 0

1 Like

Hi @wakecarter,

I uploaed my experiment to Pavlovia but the code does not work and I got the error: core.quit is not a function!
What kind of code do I need for online experiment to end the experiment for a conditional response?
I will appreciate any help.

The correct translation of core quit is on my crib sheet

I tried both of these code:
psychoJS.quit({message: 'Your custom message’});

OR

quitPsychoJS(‘Your custom message’, false);

But non of them work for me nor online neither offline.

If you try to run https://run.pavlovia.org/Wake/ebbinghaus-darts/html

you’ll see the effects of this JS code

mouseloc = mouse.getPos();
if (((mouseloc[0] === mouserec[0]) && (mouseloc[1] === mouserec[1]))) {
} else {
    if ((rec.contains(mouse) && (expInfo["researcher"] === "12345678"))) {
        mouserec = mouseloc;
        continueRoutine = false;
    } else {
        if (rec.contains(mouse)) {
            psychoJS.quit({message: 'Please click to go to the participant information sheet'});
        }
    }
}
1 Like

Hi @wakecarter,

I got an error with the link above. I don’t know where can I add my clickable response to this code and adjust it with my experiment.
I will appreciate any help.

What happens when you click on the Ebbinghaus Darts link?

It gives me this error:

@jon Any thoughts about this error? I feel like I sometimes see a red bar box briefly which then goes before I can read it.

Hi,

I tried to find another way to solve the problem. I wrote this code:
if mouse.clicked_name[0]==“polygonconsent”:
continueRoutine =False;
else:
msg = “Thank you. To exit the experiment press Esc in your keyboard.”
msgcolor=‘green’
Now, it works perfectly offline. I will upload it as soon as possible to see whether it works online.

A completely different way to approach this would be to do as you did before, i.e. with a bit of code at the end of the first routine:

if mouse.isPressedIn(text_notconsent):
    consented = 0
if mouse.isPressedIn(text_consent):
    consented = 1

Then, make a loop around your entire experiment with the number of repetitions set to the variable $consented. Finally, make an ending routine outside of the loop at the very end with a text object that says “Thank you” and a keyboard object that lets them press enter to end the experiment.
This way, if they click “I do not consent” they do the experiment zero times and arrive at the end.

1 Like

I have the same code working in one experiment and failing in another.

In Ebbinhaus Darts https://pavlovia.org/Wake/ebbinghaus-darts I have:

Each Frame

mouseloc = mouse.getPos();
if (((mouseloc[0] === mouserec[0]) && (mouseloc[1] === mouserec[1]))) {
} else {
    if ((rec.contains(mouse) && (expInfo["researcher"] === "xxx"))) {
        mouserec = mouseloc;
        continueRoutine = false;
    } else {
        if (rec.contains(mouse)) {
            psychoJS.quit({message: 'Please click to go to the participant information sheet'});
        }
    }
}

It seems to alternate between Please click to go to the participant information sheet and The [ESC] key was pressed.

In Prospective Memory LDT https://pavlovia.org/Wake/prospective-memory-ldt I have:

End Routine

if ((expInfo["researcher"] !== "xxx")) {
    psychoJS.quit({message: 'Please click to go to the participant information sheet'});
}

and I end on an error ReferenceError: message is not defined

1 Like

Unfortunately it doesn’t work online.

Dear Hamzeloo,
Did you get any solution to solve this issue?
I am also seeking the same.
Please let me know.
Thanks,
Sumathi.

Dear @Sumathi

Sorry for the delayed response. I used two polygons for the page related to the consent form and I made them clickable. Then I used this code in the tab “Each Frame”:
if mouse.clicked_name[0]==“polygonconsent”:
continueRoutine =False;
else:
msg = “Thank you. To exit the experiment press Esc on your keyboard.”
msgcolor=‘green’;
Explanation: “polygonconsent” is the name of clickable polygon for consent to participation.

I hope this works for you too.
Best regards,
Mohammad