From 8d2211b71203472461d8373dcd8d2c015cdfa351 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Tue, 24 Jun 2014 12:07:57 -0400 Subject: [PATCH] Add error message if plugin is not loaded Closes #51 --- jspsych.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jspsych.js b/jspsych.js index e5e91a35..af2c833a 100755 --- a/jspsych.js +++ b/jspsych.js @@ -324,7 +324,14 @@ // iterate through block list to create trials for (var i = 0; i < exp_blocks.length; i++) { - var trials = jsPsych[opts["experiment_structure"][i]["type"]]["create"].call(null, opts["experiment_structure"][i]); + + // check to make sure plugin is loaded + var plugin_name = experiment_structure[i].type; + if(typeof jsPsych[plugin_name] == 'undefined'){ + throw new Error("Failed attempt to create trials using plugin type "+plugin_name+". Is the plugin loaded?"); + } + + var trials = jsPsych[plugin_name]["create"].call(null, opts["experiment_structure"][i]); exp_blocks[i] = createBlock(trials); }