Null error -debug support

Student is seeing an error that reads: Error: line 51: TypeError: Cannot read properties of null (reading ‘copy’). We cannot find the error.

// Variables
var score = 0;
// Create Sprites
var egg = createSprite(350,200);
egg.setAnimation(“egg”);
egg.scale = 0.5;

var player = createSprite(200,200);
player.setAnimation(“edgarLeft”);
player.setCollider(“circle”, 0, 0, 20);

var enemy1 = createSprite();
enemy1.setCollider(“circle”);
setEnemy1();
var speed1 = randomNumber(1, 5);

var enemy2 = createSprite();
enemy2.setCollider(“circle”);
setEnemy2();
var speed2 = randomNumber(1, 5);

function draw() {
// draw the background
gameBackground();
// update the sprites
enemiesTouchCake();
movePlayer();
displaceEnemies();
enemiesTouchWater();
showScore();
drawSprites();
}

// Functions
function gameBackground() {
noStroke();
if (score >= 100) {
background(rgb(randomNumber(0, 255), randomNumber(0, 255), randomNumber(0, 255)));
} else {
background(rgb(0,100,255));
}
fill(rgb(100,100,100));
rect(0,150,400,100);
fill(rgb(80,80,80));
rect(0,140,400,10);
rect(0,250,400,10);
}

function enemiesTouchCake(){
if (enemy1.isTouching(egg)) {
score = score - 2;
setEnemy1();
}
if (enemy2.isTouching(egg)) {
score = score - 2;
setEnemy2();
}
}

function movePlayer(){
if (keyDown(“right”) && (player.x <= 400)) {
player.setAnimation(“edgarRight”);
player.velocityX = 5;
} else if (keyDown(“left”) && (player.x >= 0)) {
player.setAnimation(“edgarLeft”);
player.velocityX = -5;
} else {
player.velocityX = 0;
}

if (keyDown(“up”) && (player.y >= 0)) {
player.velocityY = -5;
} else if (keyDown(“down”) && (player.y <= 400)) {
player.velocityY = 5;
} else {
player.velocityY = 0;
}
}

function displaceEnemies(){
player.displace(enemy1);
player.displace(enemy2);
}

function enemiesTouchWater(){
if ((enemy1.y < 150) || (enemy1.y > 250)) {
score = score + 1;
setEnemy1();
}
if ((enemy2.y < 150) || (enemy2.y > 250)) {
score = score + 1;
setEnemy2();
}
}

function showScore() {
fill(“white”);
textSize(20);
text(“Score”,20,20,200,100);
text(score,20,40,200,100);
}

function setEnemy1() {
enemy1.y = randomNumber(140, 240);
enemy1.x = 0;
enemy1.setAnimation(“scary-face”);
enemy1.velocityX = speed1;
speed1 = randomNumber(1,5);
}
function setEnemy2() {
enemy2.y = randomNumber(140, 240);
enemy2.x = 0;
enemy2.setAnimation(“scary-face”);
enemy2.velocityX = speed2;
speed2 = randomNumber(1, 5);

since i do not have the test environment my knowledge will be very surface level, you are missing a brace at the end of your last function call if this is not your issue i would appreciate a link to the program you are trying to debug

Varrience

Hi @leslie.dillon,

If you didn’t get it to work with @varrience 's suggestion, please click the SHARE button of the project and paste the sharable link so we can take a look at the whole program.

Good luck!
~Michelle