Console error says I'm adding Integers and Vectors, but I only see Vectors.

I have a list of 3 Vectors, when I use the str() function to see their values I get what I except to see.

However when I use the sum() function to add the vectors together the console says I’m adding integers and Vectors, but there are only vectors in the list. :confused:


I can supply a blend file for context, but I was just wondering if this was some kind of bug.

It’s probably to do with indexes.
Try doing it without the vectors in a list.

I’m guessing this is the fault of the sum function doing something funky like taking the first element and adding it to the second list.
(I could be wrong though)

Try writing it out the long way:
myvec = Vector1() + Vector2() + Vector3()

It’s not a bug, and you can’t add two lists (or Vectors, or any iterable) together for starters unless you do something like zip() or a workaround (but you can concatenate them).
And yes, you can add two mathutils Vectors together.

EDIT: Might as well post an example:


[sum(x) for x in zip(mathutils.Vector([1, 0, 0]), mathutils.Vector([0, 1, 4]))]

Python’s sum has a signature


sum(iterable, [start])

From the docs:

Sums start and the items of an iterable from left to right and returns the total. start defaults to 0

So, the easiest solution is


sum(vectors[1:], start=vectors[0])

Might I add just a small correction? - Just take out “start=” from

 sum(vectors[1:], start=vectors[0]) 

and this should run fine.

And this is the solution I would prefer too.

You could even do it that way:


import mathutils
import bge


NULL_VECTOR = mathutils.Vector.Fill(3)


vectors = [
 mathutils.Vector((1,0,0))
,mathutils.Vector((0,1,0))
,mathutils.Vector((0,0,0))
]




sumVector = sum(vectors, NULL_VECTOR)