# Cryptic error message: t.copy is not a function

**URL:** <https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000>\
**Category:** Uncategorized\
**Created:** [September 21, 2015, 11:48am UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000 "2015-09-21T11:48:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kim\_Milvang\_Jensen](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kim\_Milvang\_Jensen](https://discourse.codecombat.com/u/Kim_Milvang_Jensen)\
**Post date:** [September 21, 2015, 11:48am UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000/1 "2015-09-21T11:48:29Z")

</div>

I have run into some problems with the Vector class.

When you give is wrong arguments. Like when I called Vector.multiply(3, retreat). I got “t.copy is not a function” error.

I also seem to have had trouble just working with positions, but cannot recreate that problem at the moment, so ill get back if I Can.

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [September 21, 2015, 1:17pm UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000/2 "2015-09-21T13:17:01Z")

</div>

What happens inside `Vector.multiply()`?

```python
# This is not exactly the code, just a simplified version for explanation-purposes
def Vector.multiply(vec, num):
    copy = vec.copy()
    copy.multiply(num)
    return copy

```

As you see the code calls `vec.copy()` without checking if `vec` is actually a vector. Now what happens if we substitute the arguments with your values:

```python
copy = 3.copy()
copy.multiply(retreat)
return copy

```

You see the problem? 3 is a number, you can not call a method from it. That is why order of arguments is _extremely_ important. You cannot simply switch those around. Computers can be extremely smart yet incredibly stupid. Modern computers will happily steer a rocket to space for you… as long as you as programmer don’t switch arguments around.

* * *

Luckily we have smart programs that can check that before we actually launch the rocket. We only have to hope that the programmers of these programs didn’t make any error…

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [October 6, 2015, 8:48am UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000/3 "2015-10-06T08:48:14Z")

</div>

Same error here, although the code seems legit to me:

```python
ahead = {"x": 5, "y": 0}
behind = Vector.multiply(ahead, -1)

```

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/ce0b0d800abf1b9192dd2e9812726787160b6da1.png)

Any ideas?

* * *

**update:** defining the variable explicitly as a vector fixes the issue:

```python
ahead = Vector(5, 0) # instead of {"x": 5, "y": 0}
behind = Vector.multiply(ahead, -1)

```

The strange thing is that e.g. `Vector.add()` works with both methods… Any explanations for that, @nick?

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [October 6, 2015, 10:33pm UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000/4 "2015-10-06T22:33:26Z")

</div>

The first argument to one of these Vector methods should be a Vector. The second one (if it takes two) can be an object.

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [October 7, 2015, 7:41am UTC](https://discourse.codecombat.com/t/cryptic-error-message-t-copy-is-not-a-function/5000/5 "2015-10-07T07:41:19Z")

</div>

Thanks for the answer.
