# Odd (Vector?) error on Broken circle level

**URL:** <https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667>\
**Category:** Uncategorized\
**Created:** [August 17, 2016, 4:05am UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667 "2016-08-17T04:05:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesM](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JamesM](https://discourse.codecombat.com/u/JamesM)\
**Post date:** [August 17, 2016, 4:05am UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/1 "2016-08-17T04:05:50Z")

</div>

While doing this level with vectors, I was getting a “TypeDef error, a.copy() is not a function” when running the below code. The error appeared on the Vector.subtract line. I also tried these but kept getting same error:  
a) center = {“x”: 68, “y”: 68}; outside the function  
b) "Vector.subtract(center,hero.pos)"  
c) “def closerPos(pos)” and passing it hero.pos.

Any one know what the problem is?

`def closerPos():
    #find a pos in a straight line between you and treasure
    # as close as possible before coming in range of a mine.
    #if there is a spot 10 units closer, report it, else, report None;
    pos = {'x':hero.pos.x,'y':hero.pos.y};
    center = {"x": 68, "y": 68};
    hero.say(pos); #here to debug and it does work saying {'x':136, 'y':67.95}
    hv = Vector.subtract(center,pos);
    hv = Vector.normalize(hv);
    hv = Vector.scale(hv,radiusStep);
    point = Vector.add(hv,pos);
    if hero.isPathClear(pos,point):
        return point;
    return None;
`

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [August 17, 2016, 5:55am UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/2 "2016-08-17T05:55:46Z")

</div>

`center` is not a `Vector`, you need to convert it to the vector if you want to operate with it that way.

---

<div class="post-metadata">

**Author:** ![JamesM](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JamesM](https://discourse.codecombat.com/u/JamesM)\
**Post date:** [August 17, 2016, 6:19am UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/3 "2016-08-17T06:19:34Z")

</div>

~~oh, wait ,why then is “center = {“x”: 68, “y”: 68};” what is provided in the level?~~ Duh to my self, so this level doesn’t need to use vector. Thanks for answering.

Edit: Curiosity question: so how come the second argument to Vector.subtract can be any object with an x and y, but not the first argument? That seems a bit weird. This seems like something that should appear in the pop up when you hover over vector in the menu below one’s code so people new to vector can understand its requirements.

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [August 17, 2016, 12:16pm UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/4 "2016-08-17T12:16:51Z")

</div>

> [@JamesM](#):
>
> Duh to my self, so this level doesn’t need to use vector.

As you want. Vectors can be useful here, but you can solve it without them.

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [August 17, 2016, 12:18pm UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/5 "2016-08-17T12:18:39Z")

</div>

> [@JamesM](#):
>
> so how come the second argument to Vector.subtract can be any object with an x and y, but not the first argument?

Your answer is [here](https://github.com/codecombat/codecombat/blob/master/app/lib/world/vector.coffee#L45). As you can see that method doesn’t check the type of the second argument, just `x` and `y` properties.

---

<div class="post-metadata">

**Author:** ![JamesM](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JamesM](https://discourse.codecombat.com/u/JamesM)\
**Post date:** [August 18, 2016, 7:50am UTC](https://discourse.codecombat.com/t/odd-vector-error-on-broken-circle-level/8667/6 "2016-08-18T07:50:05Z")

</div>

Ah, now that error message makes sense, though this is definitely a programming hazard. I hope the notes to players get updated, or the Vector class is made more robust.
