Read property 'width' undefined

Hi, I am somewhat of an intro coder for p5.js. Anyways, I am working on some code that changes a drawFunction I made on an index of images and I keep getting:
"Uncaught TypeError: Cannot read property ‘width’ of undefined


^ As Above. But that makes no sense to me considering that there is not width at drawInstructions or at draw? Does anyone have any idea why it would this is showing? I cannot get past my initial splash page in my drawFunction. Here is the code that might be related to the error. If you need more context, please let me know.
Any help will be great! Thanks!

function setup() {
    createCanvas(1280, 720);

    // Center our drawing objects
    imageMode(CENTER);
    textAlign(CENTER);
    textSize(24);

    makecontinueButton1();

    // set to one for startup
    drawFunction = drawSplash;
}

// Very simple, sets the background color and calls your state machine function
function draw() {
    // will call your state machine function
    drawFunction();
}

/************SPLASH + INTROS ********************/
//Splash Page
drawSplash = function() {
    image(images[0], 640, 360);
    continueButton1.draw();
}

//Instruction Page
drawInstructions = function() {
    image(image[19], 640, 360);
}

/**************** Buttons ***********************/
function makecontinueButton1() {
    continueButton1 = new Clickable;
    continueButton1.setImage(continueimg);
    continueButton1.color = "#00000000";
    continueButton1.width = continueimg.width;
    continueButton1.height = continueimg.height;
    continueButton1.locate(1144, 655);
}

continueButton1Pressed = function () {
if (drawFunction === drawSplash) {
	drawFunction = drawInstructions;
}
 }

Hi! Welcome to the forum!

I suppose this argument should be images and that is causing the error (internally calling p5.Image.width of image[19] which is undefined because image is a function)

    image(image[19], 640, 360);

tip - next time please try to post the whole code or at least a code that is runnable because a snippet is often not enough to debug :slight_smile:

2 Likes

Right! Will note posting the whole code next time. Thanks a lot! I literally just misspelled images hahaha

1 Like