Your program starts with dino initialized to undefined because you declare it like this, without giving it a value:
var dino;
You do have code elsewhere to assign it a value that is not undefined:
function setup() {
size(400, 400, P2D); // Set the canvas size
dino = { x: 50, y: height - 50, speed: 0 }; // Initialize 'dino' inside 'setup' function
}
Note there is a comment specifically calling out that there is a line in setup() that initializes dino to a non-default value. So it must be the case that a function that is trying to use dino.x or dino.width is getting called _before_ setup() is being called.
I hope that helps!
Mark R.
04/16/24
Samuel D.
So, I should find where dino.x or dino.width is being used before the setup function? I moved preload() to after setup() and still got the same error. I don't see where dino.x or dino.width are being called before setup(), unless it is in one of the variables I set up. var dino; var obstacles = []; var obstacleSpeed = 5; var jumpForce = -15; var gravity = 0.6; var isJumping = false; var score = 0; var dinoImg; // Declare variable for dinosaur image var cactusImg; // Declare variable for cactus image function setup() { size(400, 400, P2D); // Set the canvas size dino = { x: 50, y: height - 50, speed: 0 }; // Initialize 'dino' inside 'setup' function } function preload() { // Load pixelated images for the dinosaur and cacti dinoImg = loadImage('dinosaur.png'); cactusImg = loadImage('cactus.png'); }04/16/24