| Reference | Downloads | Github

'ReferenceError: "myfunction" is not defined' with JS although myfunction is definded (Py into JS for online self-paced moving window task experiment)

I want to conduct an experiment (online on pavlovia) with a self-paced moving window task where each word of the condition sentence is fully dashed at the beginning of the trial (-, one dash per character). And by hitting the space bar, a word gets uncovered and the previous one gets re-covered. My dependent measure is the reading time of each word in the sentence.

I prepared a minimal working example on gitlab:

I am on Windows 10 and used the PsychoPy3 (v3.2.3) Builder + some necessary code components to create the experiment. It is working perfectly fine offline in Python. The sentences get displayed correctly and also the reaction times are saved in the data-csv file.

But I have trouble translating the code components I used for making the dashes and the procedure displaying the dashes to JS code. The JS code throughs the error: ‘ReferenceError: “replaceWithDash is not defined”’ although the replaceWithDash function is defined and works correctly when I test it in isolation with a string variable in the browser.

I would be glad if you could point me to some experiments (on gitlab or github) that are Psychopy-based and are running online using a similar experimental paradigm, so I could figure it out by myself. Or if you have any hints what I did wrong with the JS code this would also be much appreciated.

Hi @edith_scheifele, I think its the way the function has been created, where it has limited scope to the experiment code tab that contains it. To get PsychoPy to give the function global scope, assign your function to a variable name:

replaceWithDash = function(WordList, currentWordNumber) {
  // etc      

1 Like

Thanks, @dvbridges! This solved the problem with the function. I really appreciate your time spent! Unfortunately, other problems showed up in the JS code that need fixing – but these are topics for another post!