@@ -781,21 +781,22 @@ export class JsPsych {
781
781
for ( const param in trial . type . info . parameters ) {
782
782
// check if parameter is complex with nested defaults
783
783
if ( trial . type . info . parameters [ param ] . type === ParameterType . COMPLEX ) {
784
- if ( trial . type . info . parameters [ param ] . array === true ) {
784
+ // check if parameter is undefined and has a default value
785
+ if ( typeof trial [ param ] === "undefined" && trial . type . info . parameters [ param ] . default ) {
786
+ trial [ param ] = trial . type . info . parameters [ param ] . default ;
787
+ }
788
+ // if parameter is an array, iterate over each entry after confirming that there are
789
+ // entries to iterate over. this is common when some parameters in a COMPLEX type have
790
+ // default values and others do not.
791
+ if ( trial . type . info . parameters [ param ] . array === true && Array . isArray ( trial [ param ] ) ) {
785
792
// iterate over each entry in the array
786
793
trial [ param ] . forEach ( function ( ip , i ) {
787
794
// check each parameter in the plugin description
788
795
for ( const p in trial . type . info . parameters [ param ] . nested ) {
789
796
if ( typeof trial [ param ] [ i ] [ p ] === "undefined" || trial [ param ] [ i ] [ p ] === null ) {
790
797
if ( typeof trial . type . info . parameters [ param ] . nested [ p ] . default === "undefined" ) {
791
798
console . error (
792
- "You must specify a value for the " +
793
- p +
794
- " parameter (nested in the " +
795
- param +
796
- " parameter) in the " +
797
- trial . type +
798
- " plugin."
799
+ `You must specify a value for the ${ p } parameter (nested in the ${ param } parameter) in the ${ trial . type . info . name } plugin.`
799
800
) ;
800
801
} else {
801
802
trial [ param ] [ i ] [ p ] = trial . type . info . parameters [ param ] . nested [ p ] . default ;
@@ -809,11 +810,7 @@ export class JsPsych {
809
810
else if ( typeof trial [ param ] === "undefined" || trial [ param ] === null ) {
810
811
if ( typeof trial . type . info . parameters [ param ] . default === "undefined" ) {
811
812
console . error (
812
- "You must specify a value for the " +
813
- param +
814
- " parameter in the " +
815
- trial . type . info . name +
816
- " plugin."
813
+ `You must specify a value for the ${ param } parameter in the ${ trial . type . info . name } plugin.`
817
814
) ;
818
815
} else {
819
816
trial [ param ] = trial . type . info . parameters [ param ] . default ;
0 commit comments