# U3L28 Function Error

**URL:** <https://forum.code.org/t/u3l28-function-error/40177>\
**Category:** Unit and Lesson Discussion\
**Tags:** csd-unit-3\
**Created:** [December 5, 2024, 6:26pm UTC](https://forum.code.org/t/u3l28-function-error/40177 "2024-12-05T18:26:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![csalinas](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@csalinas](https://forum.code.org/u/csalinas)\
**Post date:** [December 5, 2024, 6:26pm UTC](https://forum.code.org/t/u3l28-function-error/40177/1 "2024-12-05T18:26:48Z")

</div>

playerPolygoon.isTouching is not a function (line 37)

My student is receiving this error in his code but I’m not sure what the issue is. Any ideas?

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

---

<div class="post-metadata">

**Author:** ![pluto](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/pluto/32/9141_2.png) [@pluto](https://forum.code.org/u/pluto)\
**Post date:** [December 6, 2024, 4:27am UTC](https://forum.code.org/t/u3l28-function-error/40177/2 "2024-12-06T04:27:22Z")

</div>

Greetings, @csalinas .

I believe the problem lies in there that .isTouching is reserved for specifically, only sprites. “playerPolygoon” and “collectable” should be changed to sprites instead of drawings.

I hope this has helped!

~ Pluto

---

<div class="post-metadata">

**Author:** ![csalinas](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@csalinas](https://forum.code.org/u/csalinas)\
**Post date:** [December 6, 2024, 1:18pm UTC](https://forum.code.org/t/u3l28-function-error/40177/3 "2024-12-06T13:18:09Z")

</div>

Thank you! I’ve let the student know and we’ll see how it goes!

---

<div class="post-metadata">

**Author:** ![csalinas](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@csalinas](https://forum.code.org/u/csalinas)\
**Post date:** [December 6, 2024, 6:02pm UTC](https://forum.code.org/t/u3l28-function-error/40177/4 "2024-12-06T18:02:57Z")

</div>

So we looked at the code and the polygon drawing is preferred since the purpose of the game is to add a side to the polygon each time a line is collected.

Is there a way to do something similar for a variable rather than a drawing?

---

<div class="post-metadata">

**Author:** ![pluto](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/pluto/32/9141_2.png) [@pluto](https://forum.code.org/u/pluto)\
**Post date:** [December 6, 2024, 7:38pm UTC](https://forum.code.org/t/u3l28-function-error/40177/5 "2024-12-06T19:38:32Z")

</div>

Greetings once again @csalinas,

I don’t really think so, unfortunately, but there is an alternative route that you could choose (which might not be that efficient).

* * *

The only way to do this would be to set different animations for each polygon that’s shown.  
I’ve also experimented with this and you can’t tell the difference when “sides = 20-25”, so I suggest making 20-25 animations maximum and make the animation cap at the final polygon animation.

Example:

```auto
/*
Keep note that you have to name the shapes accordingly.
Example: shape3, shape4, shape5
*/

var sides = 2;
var playerPolygon = createSprite(200, 200);
var line = createSprite(200, 200);
line.setAnimation("line animation here or you could change the width and height of the sprite to make it into a line");

function draw() {
  if (playerPolygon.isTouching(line)) {
    sides += 1; //same as sides = sides + 1 | if you didn't know
  }
  if (sides >= 20) { //makes it stay at 20 if it's already 20
    sides = 20;
  }
  playerPolygon.setAnimation("shape"+sides)
  drawSprites();
}

```

If you want to make the sides still go up even after it’s maxed out at 20,

```auto
//The variable will still be changed, but the animation wont.
if (sides <= 20) {
  playerPolygon.setAnimation("shape"+sides)
} else {
  playerPolygon.setAnimation("shape20");
}

```

* * *

Sorry if this isn’t as efficient as you thought it’d be, but this was the best way I could think of.

~ Pluto

---

<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:** [December 6, 2024, 7:41pm UTC](https://forum.code.org/t/u3l28-function-error/40177/6 "2024-12-06T19:41:38Z")

</div>

I agree that this would be a decent way of solving the problem and it’s not that inefficient either!

Thanks for weighing in!

Mike

---

<div class="post-metadata">

**Author:** ![csalinas](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@csalinas](https://forum.code.org/u/csalinas)\
**Post date:** [December 6, 2024, 7:54pm UTC](https://forum.code.org/t/u3l28-function-error/40177/7 "2024-12-06T19:54:48Z")

</div>

That’s what I was thinking too but we were hoping there was a way for the polygon to keep adding to its number of sides. But this works! Thank you all!
