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
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.
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?
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
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.
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.
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.
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