Ok . this is one of the few things stopping a win for Backwoods Brawl 4. The code doesn’t error out all of the time - just on some weird spots on the edge. I’m just going to include the relevant “run-away” code. It is one of those maddening sporadic errors which do not always occur. What I suspect is that self.isPathClear(s,t) produces an error when one of the coordinates for s or t is out of bounds … but I can’t prove it.

Separate point/possible backdoor solution - went looking for Python exception handling and it appears the “try:” method is not supported. Is there a way within the code to catch and handle the exception? (Do I need an item to use that method? … Currently, Programmaticon IV equiped.)

```
---
#This function tests 9 paths to make sure the path from tarA to self.pos are clear, checking 1m in each direction from the character's center and the destination center:
def SafePath(tarA):
vecA = Vector.subtract(tarA, self.pos)
# This creates a 90° rotated, 2 m long vector relative to vec.
normV = Vector.multiply(Vector.normalize(Vector.rotate(vecA, 1.5708)), 2)
targetL = [tarA, Vector.add(tarA, normV), Vector.subtract(tarA, normV)]
startL = [self.pos, Vector.add(self.pos, normV), Vector.subtract(self.pos, normV)]
isFree = True
for s in startL: #Testing the 3 positions around the self.pos
for t in targetL: #Testing the 3 positions around the tarA
if s and t:
isFree = isFree and self.isPathClear(s, t) #this is the line which gives errors sometimes
else:
isFree = False
return isFree
#Moves 1 step towards tarA. If the path to tarA is obstructed, rotates around 28 degrees and tries again.
def SafeMove(tarA):
tarLoc = tarA
cAngle = 0
adjAngle = 0.5
while (not( SafePath(tarLoc)) and (cAngle < 2*Math.PI)):
vecA = Vector.normalize(Vector.subtract(tarLoc, self.pos))
vecB = Vector.normalize(Vector.rotate(vecA, adjAngle))
tarLoc = Vector.add(self.pos, vecB)
cAngle = cAngle + adjAngle
self.move(tarLoc)
loop:
break
loop:
enemies = self.findEnemies()
MoveVector = Vector(0,0)
#This next loop calculates the destination Vector based on the weighted sum of each enemy vector. And yes, I do have an additional 28 degree turn added.
for enemy in enemies:
weight = enemy.health / (self.distanceTo(enemy)^2)
eVector = Vector.multiply(Vector.rotate(Vector.subtract(self.pos, enemy.pos),0.5),weight)
MoveVector = Vector.add(MoveVector, eVector)
tarA = Vector.add(self.pos, Vector.multiply(Vector.normalize(MoveVector),2))
SafeMove(tarA)
```