Pass image path into loadimage

I am having the problem where I want to pass a variable with image path into loadImage(). However, I am getting the error:


This must be possible but I don’t see anything in docs or online demonstrating this.

please link to your project at so we can see the file, the code,
( also check the p5.js revision )
and can play


Hey there, here’s the link:

Im not working in the editor btw. The error I am getting now is different.


display() {
      var loadedImage = loadImage(this.imgPath);  

you should not load that image every time draw() // .display() runs


Thanks, I didnt want to load the image and save it as an attribute because i wanted to save an instance of a computer as json, but i was getting this error because of loading an image as an attribute. Do you know a work around for this?

Thanks for the help

no idea what you want to save?

function draw() {
  comp.move(mouseX, mouseY);

  json = JSON.stringify(comp);

  saveJSON(json, 'comp.json');


but that would give you about 50 download windows per sec!