Error: jsPsych.timelineVariable is not a function #2484
-
Hello, I'm super new to JavaScript and jsPsych. I'm coding a recognition memory experiment. I've set it up so that I have a "main" index.html script that does the job of obtaining consent, showing instructions etc. Then there is an EncodingPhase.js that presents the stimuli for the encoding phase. For this purpose I'm using timeline variables as explained in the Reaction Time tutorial and here. For some reason, however, I'm getting the error "jsPsych.timelineVariable is not a function", that points to the first time timelineVariable is used in EncodingPhase.js. I'm using the exact same structure as the example in the link above. Is this error originating because I have this two-script setup? How do I fix it? Here are the two scripts: index.html:
EncodingPhase.js
Sorry if I'm missing something obvious! This is Day 5 of me using JavaScript! Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @mrinmayik, welcome to the jsPsych community! No need to be apologetic - most researchers have very little JS experience. We're here to help 😃 I think the reason for this error is because the code in your EncodingPhase.js file references a jsPsych function ( var jsPsych = initJsPsych(); Here are some options:
Options 1 and 2 may not be ideal if you want to write your experiment in a modular way, whereas option 3 would allow you to keep the encoding phase code separate and more reusable across different experiments. Can you let us know if any of those solutions work for you? Btw it looks like your encoding phase code references an array called |
Beta Was this translation helpful? Give feedback.
Hi @mrinmayik, welcome to the jsPsych community! No need to be apologetic - most researchers have very little JS experience. We're here to help 😃
I think the reason for this error is because the code in your EncodingPhase.js file references a jsPsych function (
jsPsych.timelineVariable
) and that file is loaded before your main script. So when the EncodingPhase file loads, thejsPsych
variable hasn't been created yet - it's created in this line in your main script:Here are some options: