TypeError: Cannot read properties of undefined (reading '0'). Experiment works properly locally, does not work when piloted online

URL of experiment: ranking_study [PsychoPy]

Description of the problem:

I have created a ranking study with PsychPy and it works perfectly when run locally. However, when I sync the experiment to Pavlovia and try to pilot it online, I get this error:

Error Unfortunately we encountered the following error: * TypeError: Cannot read properties of undefined (reading ‘0’) Try to run the experiment again. If the error persists, contact the experiment designer.

Screenshot 2023-04-05 181938

I think that this error message might be due to Pavlovia having issues with the branching elements to my experiment.

Participants are asked to consent to a list of statements.

If they do not consent they are sent to a noConsentScreen where they are asked if they are sure that they do not consent. To do this, I have created a trial at the beginning of my experiment called ‘consentScreen’, which has a code segment in builder called ‘consent_code_1’ and contains the following code:

if mouse_resp.clicked_name == ['green_box']:
    consented = True
    show_trial_loop_reps = 1
    no_consent_loop_reps = 0
    # new_consent_screen.finished = True
elif mouse_resp.clicked_name == ['red_box']:
    consented = False
    show_trial_loop_reps = 0
    no_consent_loop_reps = 1
    # new_consent_screen.finished = True

If partipants do not consent and are shown the noConsentScreen they have the option to try and consent again or to exit the application. The code for this is as follows:

if mouse_exit_consent_resp.clicked_name == ['exitText']:
    consented = False
    show_trial_loop_reps = 0
     # added at 18:01 05/04/23
    no_consent_loop_reps = 1
    # new_consent_screen.finished = True
elif mouse_exit_consent_resp.clicked_name == ['returnText']:
    consented = True
    show_trial_loop_reps = 1
    # added at 18:01 05/04/23
    no_consent_loop_reps = 0
    # new_consent_screen.finished = True

The new consent screen allows them to consent again or to exit the study completely:

if mouse_resp_2.clicked_name == ['green_box_3']:
    consented = True
    show_trial_loop_reps = 1
    no_consent_loop_reps = 0
    # new_consent_screen.finished = True
elif mouse_resp_2.clicked_name == ['red_box_3']:
    consented = False
    show_trial_loop_reps = 0
    no_consent_loop_reps = 1
    # new_consent_screen.finished = True

I am pretty new to PsychoPy and I was wondering if Pavlovia doesn’t like the way I branched my study or if it is a completely different reason why I am getting this error message.

When I open up the console in my browser when I get the error message for my experiment, I get the following error messages:
TypeError: Cannot read properties of undefined (reading ‘0’)
at Object.next (TrialHandler.js:158:47)
at Scheduler._currentTask (ranking_study.js:1513:16)
at Scheduler._runNextTasks (Scheduler.js:215:24)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async update (Scheduler.js:136:18)
window.onunhandledrejection @ PsychoJS.js:730
log4javascript.js:148 FATAL 18:42:03.374 _GUI.dialog psychojs-2022.2.4.js:1257 | {}
BrowserConsoleAppender.append @ log4javascript.js:148
TrialHandler.js:158 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘0’)
at Object.next (TrialHandler.js:158:47)
at Scheduler._currentTask (ranking_study.js:1513:16)
at Scheduler._runNextTasks (Scheduler.js:215:24)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async update (Scheduler.js:136:18)

Here is the psyexp file for my study:
ranking_study.psyexp (216.2 KB)

As I had thought, the problem was in the code. While Python understood my code perfectly, the transition to online did not work as it couldn’t be read properly in JS.

The solution is as follows (if anyone else has this issue in the future):

if mouse_resp.clicked_name[0] == 'green_box':
    consented = True
    show_trial_reps = 1
    no_consent_loop_reps = 0

elif mouse_resp.clicked_name[0] == 'red_box':
    consented = False
    show_trial_reps = 0
    no_consent_loop_reps = 1

It was purely a syntax error.