I am developing an experiment and running it on the Pavlovia platform. The experiment involves dynamically updating two image components (image1 and image2) during the task. I attempted to update the image paths using the following code:
However, the following error appears in the browser console during execution:
arduino
PsychoJS.js:873 ReferenceError: image1 is not defined
at Scheduler._currentTask (igt.js:1579:10)
at Scheduler._runNextTasks (Scheduler.js:225:24)
at async Scheduler._runNextTasks (Scheduler.js:232:13)
at async Scheduler._runNextTasks (Scheduler.js:232:13)
at async update (Scheduler.js:139:18)
Relevant Code Snippet:
Here is the key part of my code where the error occurs:
javascript
if (_pj.in_es6(choice_resp.keys, choices)) {
let [show1, show2, win_list, lose_list] = choices[choice_resp.keys];
// Attempt to update the image components
image1.image = "reward.bmp";
image2.image = "punishment.bmp";
}
Could you please advise on how to resolve this issue?
Thank you for your suggestion. I have already replaced the image format with PNG as recommended. Below is the complete Python code I’m using, but I’m still encountering errors. Could you please take a look and advise?
Since image1 is an image component then image1 is not defined either means that your code is in Begin or Before Experiment or you are also using image1 for something else as well.
Thank you for your suggestion. The error “image1 is not defined” is indeed appearing, but my code is in the “End Routine” section, not in “Begin” or “Before Experiment.” Also, I am not using image1 for anything else. Could there be another reason for this issue?
image1 is not the name of an image component. It is a variable that you try to set to be an image object. It therefore probably needs to be defined in the same way as other variables. My crossed out answer in Help Request: ReferenceError: image1 is not defined - #3 by wakecarter still stands.
Try image1 = 0 in Begin Experiment. I think it should be okay not to be set to be an image object. The important thing is to give the variable image1 scope across the whole experiment.