# ERROR: Line: 99: TypeError: player.collide is not a function

**URL:** <https://forum.code.org/t/error-line-99-typeerror-player-collide-is-not-a-function/31831>\
**Category:** CS Discoveries\
**Tags:** csd-unit-3-lesson-21\
**Created:** [December 3, 2019, 7:37pm UTC](https://forum.code.org/t/error-line-99-typeerror-player-collide-is-not-a-function/31831 "2019-12-03T19:37:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joell.boast](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joell.boast](https://forum.code.org/u/joell.boast)\
**Post date:** [December 3, 2019, 7:37pm UTC](https://forum.code.org/t/error-line-99-typeerror-player-collide-is-not-a-function/31831/1 "2019-12-03T19:37:46Z")

</div>

I am not sure how to resolve this error message for this student. The code runs for almost 5 secs and then errors out? ERROR: Line: 99: TypeError: player.collide is not a function  
Any help is appreciated.

// Variables  
var score = 0;

// Create Sprites  
var player = createSprite(200, 200);  
player.setAnimation(“alien”);  
var star1 = createSprite(randomNumber(0, 400), 0);  
star1.setAnimation(“star”);  
var star2 = createSprite(randomNumber(0, 400), 0);  
star2.setAnimation(“star”);  
var platform1 = createSprite(100, 0);  
platform1.setAnimation(“platform”);  
platform1.velocityY = 1;  
var platform2 = createSprite(300, 200);  
platform2.setAnimation(“platform”);  
platform2.velocityY = 1;  
star1.velocityY = 2;  
star2.velocityY = 2;

function draw() {  
// draw the background  
background1();  
if (score \>= 15) {  
background2();  
}  
controlPlayer();  
playerLands();  
showScore();  
loopPlatform();  
loopItems();  
playerFall();  
collectItems();  
// update the sprites

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(“blue”);  
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 showScore() {  
fill(“white”);  
textSize(20);  
text(“Score:” + score,10, 10, 80, 20);  
}  
function loopPlatform() {  
if (platform1.y \>= 410) {  
platform1.x = randomNumber(0, 400);  
platform1.y = -5;  
}  
if (platform2.y \>= 410) {  
platform2.x = randomNumber(0, 400);  
platform2.y = -5;  
}  
}  
function loopItems() {  
if (star1.y \>= 400) {  
star1.x = randomNumber(0, 400);  
star1.y = 0;  
}  
if (star2.y \>= 400) {  
star2.x = randomNumber(0, 400);  
star2.y = 0;  
}  
}  
function playerFall() {  
player.velocityY = 2;  
}  
function controlPlayer() {  
if (keyDown(“right”)) {  
player.x = player.x + 2;  
}  
if (keyDown(“left”)) {  
player = player.x - 2;  
}  
if (keyDown(“up”)) {  
player.y = player.y + -5;  
}  
}  
_function playerLands() {_

- player.collide(platform1);\*
- player.collide(platform2);\*  
_}_  
function collectItems() {  
if (player.isTouching(star1)) {  
star1.x = randomNumber(0, 400);  
star1.y = 0;  
score = score + 1;  
}  
if (player.isTouching(star2)) {  
star2.x = randomNumber(0, 400);  
star2.y = 0;  
score = score + 1;  
}  
}

---

<div class="post-metadata">

**Author:** ![elizabeth\_admin](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@elizabeth\_admin](https://forum.code.org/u/elizabeth_admin)\
**Post date:** [December 3, 2019, 8:56pm UTC](https://forum.code.org/t/error-line-99-typeerror-player-collide-is-not-a-function/31831/2 "2019-12-03T20:56:41Z")

</div>

Hi Joell,

`collide` is a method/function that is automatically there for any sprite. If `player.collide` isn’t a function, that means that `player` isn’t a sprite anymore. I’d have the student check over the code for somewhere that the `player` variable was assigned something that is not a sprite, probably because the student meant to assign something to a sprite property, but instead assigned the value to the entire sprite, thus knocking the sprite out of the variable and leaving a new (non-sprite) value there instead.

You could also use watchers to “watch” `player` . Eventually, it will change from a sprite to something else, and you’l know when the problem shows up.

Elizabeth
