Running a code script if the experiment was exited using the escape key

Hello all,

My use case is this. I want to alter the final Pavlovia “message” text that is shown in the dialog box that appears after the data is saved if the user quit out of the experiment early using the Escape key. E.g., the current text is

Thank you for your patience.
The [Escape] key was pressed. Goodbye!"

And I want it to read:

"Thank you for your patience. [n.b., I don’t think this sentence can be changed]
‘It appears that you did not finish the game. Please click OK and write an email to the experimenter to let him know.’

Now I know that I can alter this text by using a code component that sets the value of “message” at the end of the experiment, e.g.,

message = ‘It appears that you did not finish the game. Please click OK and write an email to the experimenter to let him know.’

However, I want one message to be shown if the user finishes the experiment normally (which I know how to do) and a different message to be shown if they quit early. So I’m thinking I need a script that accomplishes something like this pseudo code

If hypothetical_user_quit_flag_variable = 1:
message = ‘It appears that you did not finish the game. Please click OK and write an email to the experimenter to let him know.’

I know this is theoretically possible since Pavlovia clearly alters the ending message if the users quits early, and because the Experiment Settings can be configured to send the user to a different URL if they quit the experiment.

Thus my question: how do you write a code component that runs if and only if the participant quit out of the experiment early?

After posting this, I saw this information in the Python to Java Script crib sheet about JS code that you can use to change the quit message.

core.quit()
psychoJS.quit({message: 'Your custom message’}); OR
quitPsychoJS(‘Your custom message’, false);
More testing needed.

You should also be able to add to the standard message by setting the variable in PsychoPy, e.g. message = “Please click ‘ok’ to be debriefed.”; in the End Experiment tab of code_JS

I don’t think this addresses my issue though. I think it only lets you set a custom message if you make the user quit inside of a code block. It’s unclear how you would apply this to changing the message of the quit function that is triggered by pressing the escape key. Also, it would be best if there was a generalized solution that allows the the experimenter to run arbitrary code when a user quits out of the experiment.

I think what you need is to activate the code when the user is no longer in full screen

Thanks for your response wakecarter:

(1)

How do you do that? (feel free to just tell me that it’s in the crib sheet, haven’t checked yet)

(2) What about a participant who exits full screen but finishes the experiment in windowed mode? Maybe we just want to quit those people out and tell them to start again, but they are at least theoretically differentiable.

Illustrative use case: what if you want PsychoPy/Pavlovia to tell the participant “Please press the F11 key to return to full screen and continue the expierment” if they exit full screen and then if they press escape again to exit, show them the message “You exited the experiment early, please email the experimenter to let him know.”

To be honest I’m not sure if it’s in the crib sheet. It might be in the code examples at the bottom. I am sure I’ve read relevant discussions on the forum about both escape and full screen

K. I tried several searches to try and find the relevant posts in the forums, but came up short. I’ll try poking around again, though very glad if anyone can point something out to me or has a solution :slight_smile:

Here’s a couple that might help

Thank you @wakecarter. I’ll read these in detail, see if I come up with a solution, and let you know here.