Kilear
October 28, 2015, 4:34pm
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?
jbum
November 16, 2015, 9:17pm
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.
ant
November 16, 2015, 11:19pm
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
jbum
November 18, 2015, 7:48pm
4
That fixed it. Thanks so much!
jxcwzk
March 21, 2019, 2:53am
5
maybe you can define the vector of each enemy like:
vecEnemy = Vector(enemy.pos.x,enemy.pos.y)
then use add