ERROR: Line: 23: Error: Error: overlap can only be checked between sprites or groups HELP

I have many students get this error and I can not figure out how to fix it.
ERROR: Line: 23: Error: Error: overlap can only be checked between sprites or groups

Here is my current student’s code:
// Variables
var score;
var plat = createSprite(100,0);
var plat2 = createSprite(300,250);
var star = createSprite(randomNumber(100,300),randomNumber(0,250));
var star2 = createSprite(randomNumber(100,300),randomNumber(0,250));
var playerFall = createSprite(200,0);

// Create Sprites
plat.setAnimation(“platform”);
plat.velocityY = 2;
plat2.setAnimation(“platform”);
plat2.velocityY = 2;
star.setAnimation(“star”);
star.velocityY = 2;
star2.setAnimation(“star”);
star2.velocityY = 2;
playerFall.setAnimation(“alien”);
playerFall.velocityY = 3;
playerFall.collide(edges);
function draw() {
*(Line 23) background1();
showScore();

// update the sprites
if(score === 100) {
background2();
}

controlPlayer();
loopPlatforms();
loopItem();
score = 0;
playerLands();
drawSprites();
}

// Functions
function background1() {
background(“darkBlue”);
noStroke();
fill(“yellow”);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(340, 50, 60, 60);
fill(“darkBlue”);
ellipse(320, 30, 60, 60);
}
function background2() {
background(“lightblue”);
noStroke();
fill(“black”);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(340, 50, 60, 60);
fill(“lightblue”);
ellipse(320, 30, 60, 60);
}
function showScore() {
fill(“white”);
textSize(20);
text("Score: ",10, 10, 80, 20);
}
function loopPlatforms() {
if(plat.y > 400) {
plat.y = 0;

}
if(plat2.y > 400) {
plat2.y = 0;

}

}
function loopItem() {
if(star.y > 400) {
star.y = 0;
star.x = randomNumber(0,400);
}
if(star2.y > 400) {
star2.y = 0;
star2.x = randomNumber(0,400);
}
}
function controlPlayer() {

if(keyDown(“up”)) {
playerFall.velocityY = playerFall.velocityY - 3;
}
if(keyDown(“down”)) {
playerFall.velocityY = playerFall.velocityY + 3;
}
if(keyDown(“left”)) {
playerFall.x = playerFall.x - 3;
playerFall.setAnimation(“alien_copy_1”);
}
if(keyDown(“right”)) {
playerFall.x = playerFall.x + 3;
playerFall.setAnimation(“alien”);
}
}
function playerLands() {
playerFall.collide(plat);
playerFall.collide(plat2);
}

Hi Jason,

I think the problem is actually two lines up. “overlap” is the method that checks whether sprites are overlapping when you run collisions on them, so every time “collide” is called, “overlap” is called behind the scenes.

In the line playerFall.collide(edges);, the student tried to run a collision with the edges, but they have not been defined yet. The student needs to create edge sprites and save them into the variable “edges” for this to work.

Elizabeth

2 Likes

Thank you soo much , elizabeth this helped a lot. :slight_smile: