Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Cannon read property "read" of undefined in Polygonception

#1

I tried solving “Polygonception” from the Glacier using the technique shown in previous levels, but for some reason I keep getting the error above.

Here’s what I’m doing:

startOffset = Vector(-15, -15)
endOffset = Vector(15, -15)
enemies = self.findEnemies()
for enemy in enemies:
    start = Vector.add(enemy.pos, startOffset) 
    end = Vector.add(enemy.pos, endOffset)
    sides = enemy.sides
    polygon(start, end, sides)

where polygon is defined as follows:

def polygon(start, end, side):
    full = Vector.subtract(end, start)
......................

At the very first line of polygon the error appers. What am I doing wrong?

0 Likes

#2

I’m curious if you got past this because I am having the same problem. I believe I am passing valid vectors to the drawPolygon function, but inside the function it is treating them as undefined. My code looks very similar to yours.

0 Likes

PolygonCeption - Need Help
#3

There is a known bug in the python parser, this may cause the problem. The workaround is the following:

def polygon(start_, end_, side):
    start = start_
    end = end_
    full = Vector.subtract(end, start)
    # continue your code here
0 Likes

#4

That fixed it. Thanks so much!

0 Likes

#5

maybe you can define the vector of each enemy like:

vecEnemy = Vector(enemy.pos.x,enemy.pos.y)

then use add

0 Likes