# Unit 3 Lesson 22 help

**URL:** <https://forum.code.org/t/unit-3-lesson-22-help/31048>\
**Category:** Coding and Debugging Help\
**Created:** [October 3, 2019, 3:41pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048 "2019-10-03T15:41:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![leachlisa](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@leachlisa](https://forum.code.org/u/leachlisa)\
**Post date:** [October 3, 2019, 3:41pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/1 "2019-10-03T15:41:29Z")

</div>

> **[Code.org](https://studio.code.org/users/sign_in)**
>
> Anyone can learn computer science. Make games, apps and art with code.

This is a student project, so I don’t know it you can view it ![code](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/b/b21c6e7d5a5c03e3d8f6e2659e0f48ad50d22570.png)  
He is getting the error message: ERROR: Line: 170: Error: Error: overlap can only be checked between sprites or groups. I don’t know what that means.

---

<div class="post-metadata">

**Author:** ![karenma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/karenma/32/4924_2.png) [@karenma](https://forum.code.org/u/karenma)\
**Post date:** [October 4, 2019, 1:11am UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/2 "2019-10-04T01:11:46Z")

</div>

Hi Lisa,

It would be very helpful and make it easier for us to help, if you could fill out the template in the debugging category. The information includes the following:

- Share a link to the project / level that’s giving them trouble
  - A description of what specifically you expect to happen, ideally talking about a specific element on the screen or specific lines of code
  - A description of what happens instead
  - A description of what you already have tried to solve the problem
  - The more details the better

---

<div class="post-metadata">

**Author:** ![leachlisa](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@leachlisa](https://forum.code.org/u/leachlisa)\
**Post date:** [October 4, 2019, 3:29pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/3 "2019-10-04T15:29:13Z")

</div>

Here is the code for the issue:

// Create your variables here  
var score;  
var life;  
life = 100;  
score = 0;  
var fun;  
fun = randomNumber(1, 3);

// Create your sprites here  
var boi = createSprite(200, 200);  
var alien = createSprite(200, 0);  
var b = createSprite(boi.x, boi.y);  
var hole\_1 = createSprite(randomNumber(0, 400), randomNumber(0, 400));  
var hole\_2 = createSprite(randomNumber(0, 400), randomNumber(0, 400));  
var hole\_3 = createSprite(randomNumber(0, 400), randomNumber(0, 400));  
b.setAnimation(“axe\_iron\_1”);  
hole\_2.setAnimation(“hole”);  
hole\_1.setAnimation(“hole”);  
hole\_3.setAnimation(“hole”);  
hole\_1.visible = 0;  
hole\_2.visible = 0;  
hole\_3.visible = 0;  
boi.setAnimation(“boi\_1”);  
boi.scale = 0.5;  
b.scale = 0.2;  
b.visible = 0;  
alien.velocityY = 3;

function draw() {  
hit();  
b.rotationSpeed = 21;  
if (fun == 1) {  
alien.setAnimation(“alienBlue\_bounce\_1”);  
}  
if (fun == 2) {  
alien.setAnimation(“alienBlue\_bounce\_1\_copy\_2”);  
}  
if (fun == 3) {  
alien.setAnimation(“alienBlue\_bounce\_1\_copy\_1”);  
b.setAnimation(“blender\_1”);  
}  
if (alien.isTouching(boi)) {  
alien = 200;  
alien.y = 0;  
life = life - 10;  
}  
if (life == 0) {  
alien.velocityX = 0;  
alien.velocityY = 0;  
boi.velocityX = 0;  
boi.velocityY = 0;  
b.velocityX = 0;  
b.velocityY = 0;  
playSound(“yeeet.mp3”, false);  
playSound(“yeet.mp3”, false);  
}  
if (score \>= 1000) {  
hole\_1.visible = 100;  
hole\_2.visible = 100;  
background(“yellow”);  
hole\_1.displace(boi);  
hole\_2.displace(boi);  
}  
if (score \>= 2000) {  
hole\_3.visible = 100;  
background(“purple”);  
hole\_3.displace(boi);  
}  
// draw background  
move();  
if ((alien.y) \<= 0) {  
alien.velocityY = randomNumber(4, 6);  
alien.velocityX = randomNumber(4, 6);  
}  
if (alien.y \>= 400) {  
alien.velocityY = randomNumber(-4, -6);  
alien.velocityX = randomNumber(-4, -6);  
}  
if ((alien.x) \<= 0) {  
alien.velocityY = randomNumber(4, 6);  
alien.velocityX = randomNumber(4, 6);  
}  
if (alien.x \>= 400) {  
alien.velocityY = randomNumber(-4, -6);  
alien.velocityX = randomNumber(-4, -6);  
}  
if ((boi.y) \<= 0) {  
boi.velocityY = 5;  
}  
if (boi.y \>= 400) {  
boi.velocityY = -5;  
}  
if ((boi.x) \<= 0) {  
boi.velocityX = 5;  
}  
if (boi.x \>= 400) {  
boi.velocityX = -5;  
}  
background(“grey”);  
fill(“black”);  
textSize(20);  
text(“Score:”, 5, 5, 20, 20);  
text(score , 70, 5, 20, 20);  
fill(“black”);  
textSize(20);  
text(“Life:”, 5, 50, 20, 20);  
text(life , 50, 50, 20, 20);

// update sprites

drawSprites();  
}  
function move() {  
if (keyWentDown(“w”)) {  
b.x = boi.x;  
b.y = boi.y;  
b.velocityY = -3;  
b.velocityX = 0;  
b.visible = 100;  
}  
if (keyWentDown(“s”)) {  
b.visible = 100;  
b.x = boi.x;  
b.y = boi.y;  
b.velocityY = 3;  
b.velocityX = 0;  
}  
if (keyWentDown(“d”)) {  
b.x = boi.x;  
b.y = boi.y;  
b.visible = 100;  
b.velocityX = 3;  
b.velocityY = 0;  
}  
if (keyWentDown(“a”)) {  
b.x = boi.x;  
b.y = boi.y;  
b.visible = 100;  
b.velocityX = -3;  
b.velocityY = 0;  
}  
if (keyWentDown(“left”)) {  
boi.velocityX = -5;  
boi.setAnimation(“Boi\_2”);  
}  
if (keyWentUp(“left”)) {  
boi.velocityX = 0;  
}  
if (keyWentDown(“right”)) {  
boi.velocityX = 5;  
boi.setAnimation(“boi\_1”);  
}  
if (keyWentUp(“right”)) {  
boi.velocityX = 0;  
}  
if (keyWentDown(“down”)) {  
boi.velocityY = 5;  
}  
if (keyWentUp(“down”)) {  
boi.velocityY = 0;  
}  
if (keyWentDown(“up”)) {  
boi.velocityY = -5;  
}  
if (keyWentUp(“up”)) {  
boi.velocityY = 0;  
}  
}  
function hit() {  
if (b.isTouching(alien)) { **This is where the red box appears. Line 170** }  
b.visible = 0;  
b.x = 420;  
b.y = 420;  
alien.x = 200;  
alien.y = 0;  
b.velocityY = 0;  
b.velocityX = 0;  
score = score + 100;  
}  
}

The code works but when boi touches alien, the game stops with the following error message “ERROR: Line: 170: Error: Error: overlap can only be checked between sprites or groups”. I have no idea what overlap means.

---

<div class="post-metadata">

**Author:** ![melynn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/melynn/32/4925_2.png) [@melynn](https://forum.code.org/u/melynn)\
**Post date:** [October 4, 2019, 3:46pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/4 "2019-10-04T15:46:37Z")

</div>

Hi Lisa,

Can your student click SHARE, copy the link, and then send to you so you can post it here? Being able to access all the sprites and tabs would help problem solving.

Thank you,  
Michelle

---

<div class="post-metadata">

**Author:** ![leachlisa](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@leachlisa](https://forum.code.org/u/leachlisa)\
**Post date:** [October 7, 2019, 3:31pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/5 "2019-10-07T15:31:21Z")

</div>

It is shared. Here is the link: [https://studio.code.org/s/csd3-2019/stage/22/puzzle/9](https://studio.code.org/s/csd3-2019/stage/22/puzzle/9)

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 7, 2019, 3:38pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/6 "2019-10-07T15:38:21Z")

</div>

@leachlisa unfortunately, that’s just the generic link to that stage of unit 3 in CSD. To get the link to the student’s specific project, he will have to click the “Remix” button and then the “Share” button and then we will have the exact link to his project and be able to look and see what the error is doing.

Sorry for the extra work!

Mike

---

<div class="post-metadata">

**Author:** ![leachlisa](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@leachlisa](https://forum.code.org/u/leachlisa)\
**Post date:** [October 7, 2019, 3:50pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/7 "2019-10-07T15:50:34Z")

</div>

Sorry. Here is the link\>

> **[Code.org](https://studio.code.org/users/sign_in)**
>
> Anyone can learn computer science. Make games, apps and art with code.

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 7, 2019, 4:06pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/8 "2019-10-07T16:06:59Z")

</div>

All I’m seeing in that link is the [code.org](http://code.org) sign in link:

“[https://studio.code.org/users/sign\_in](https://studio.code.org/users/sign_in)”

Does your link look different? It should be longer.

Mike

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 7, 2019, 4:18pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/9 "2019-10-07T16:18:46Z")

</div>

Also, one quick thing … I was able to “somewhat” recreate his program using his code and adding my own sprites. I’m sure it looks different than his, but I can see that error code. Not sure yet that I’ve fully isolated the problem, but if I move the “boi” out of the way, the alien does hit the axe and the intended code does run, the score updates, etc. My first thought is that it’s something to do with having the boy in the way of the collision, but I’m not sure why that is throwing an error. That’s just my first attempt at it and it would be easier with a link to his code using his animations so I can better see what he is trying to do exactly.

thanks,

Mike

---

<div class="post-metadata">

**Author:** ![leachlisa](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@leachlisa](https://forum.code.org/u/leachlisa)\
**Post date:** [October 7, 2019, 4:19pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/10 "2019-10-07T16:19:32Z")

</div>

> **[Check out what I made](https://studio.code.org/projects/gamelab/2QEb0Xc2R3sB8k02yCOUWqBlRva0Rgaw6Jkz9LPRS8U)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 7, 2019, 4:24pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/11 "2019-10-07T16:24:01Z")

</div>

Another quick observation, the error seems to completely go away in my version if you change line 170 to read:

if (boi.isTouching(alien)){

this checks for a collision between the boy and the alien. Not sure if that’s what he is after, but it may be helpful if he plugs that in. It may give him some inspiration.

Mike

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 7, 2019, 4:27pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/12 "2019-10-07T16:27:06Z")

</div>

Ok… just got your link. I did that same change I mentioned in line 170

if (boi.isTouching(alien)){

It seems to solve the problem most of the time, but the error sometime still reoccurs. I’ll see if I can get another pair of eyes on it, but that substitution does work better even if not yet perfect.

Mike

---

<div class="post-metadata">

**Author:** ![melynn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/melynn/32/4925_2.png) [@melynn](https://forum.code.org/u/melynn)\
**Post date:** [October 7, 2019, 6:03pm UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/13 "2019-10-07T18:03:21Z")

</div>

Let me see if I can tackle this…

First, I usually like to go top to bottom to find the error but this one was harder to do that because of the function calls. So, I tried to figure out what the student wanted to do with the axe (b). It looks like it was a weapon. My thinking was the overlap error was generated because the boi and axe were connected so I thought if you separated them in the conditional, it may work (or at least be more accurate). So, my thinking said “if the axe is visible AND it is touching the alien, then you should call the function hit”. The student had the function hit running at the top of the draw loop. When I changed this, an error came up about alien not being a function. I found a [great post](https://forum.code.org/t/need-help-with-an-error/24238/2) by @elizabeth_admin that talks about his. Your student did have alien=200 (vs alien.x or alien.y). When I took out this line, there does not seem to be an error but I am open to the idea that one is still there if the game is played enough. Also, my version takes out the fun variable (that randomly generates an alien animation) but it should go back in without a problem.

Also, many of the sprite.visible properties are set to a number but it is a boolean property meaning it is either true or false only (not a number). Here is some documentation on [sprite.visible](https://docs.code.org/gamelab/visible/).

Let us know if these tips help out or if I missed the mark (or the alien-ha!) Here is my remix: [https://studio.code.org/projects/gamelab/ags5A5O-qzXbi3rMVwbYH8SPW61r7uk38Yrw4CwYGYk](https://studio.code.org/projects/gamelab/ags5A5O-qzXbi3rMVwbYH8SPW61r7uk38Yrw4CwYGYk)

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 8, 2019, 1:52am UTC](https://forum.code.org/t/unit-3-lesson-22-help/31048/14 "2019-10-08T01:52:26Z")

</div>

@melynn is right. I missed the line (43, I believe), where he coded alien=200; It looks like he meant to write alien.x = 200; I’m sure that’s the line of code that is throwing the error because it tried to turn a sprite (alien) into a regular variable with a value so when it started checking for the collision, it couldn’t find the “sprite” called alien because it had been changed into a variable.

Thanks @melynn!

Mike
