I'm writing a script using python for finding a path for the object to move to (I know the RTS movement works for this). It's not complete, and it probably isn't the best written. One problem I'm running into is that it seems to run through the script only once. It's not under any construct events. Here's what I have so far.

[code:2buu5dmb]

#Pathfinding

from math import sqrt

d = sqrt(((unit.X-goal.X)**2)+((unit.Y-goal.Y)**2))

findpath = 'false'

if System.globalvar('start') == "yes":

findpath = 'true'

if findpath == 'true':

findpath == 'false'

distance.SetText(d)

pX = unit.X

pY = unit.Y

listX = []

listY = []

listX.append(pX)

listY.append(pY)

whileloop = 'yes'

while whileloop == 'yes':

p1 = sqrt((((pX+1)- goal.X)**2)+ (((pY+1)-goal.Y)**2))

p2 = sqrt((((pX+1)- goal.X)**2)+ (((pY)-goal.Y)**2))

p3 = sqrt((((pX+1)- goal.X)**2)+ (((pY-1)-goal.Y)**2))

p4 = sqrt((((pX)- goal.X)**2)+ (((pY-1)-goal.Y)**2))

p5 = sqrt((((pX-1)- goal.X)**2)+ (((pY-1)-goal.Y)**2))

p6 = sqrt((((pX-1)- goal.X)**2)+ (((pY)-goal.Y)**2))

p7 = sqrt((((pX-1)- goal.X)**2)+ (((pY+1)-goal.Y)**2))

p8 = sqrt((((pX)- goal.X)**2)+ (((pY+1)-goal.Y)**2))

choice = min(p1,p2,p3,p4,p5,p6,p7,p8)

n = 0

if n == 0:

if p1 == choice:

choice = [pX+1,pY+1]

n = 1

elif p2 == choice:

choice = [pX+1,pY]

n = 1

elif p3 == choice:

choice = [pX+1,pY-1]

n = 1

elif p4 == choice:

choice = [pX,pY-1]

n = 1

elif p5 == choice:

choice = [pX-1,pY-1]

n = 1

elif p6 == choice:

choice = [pX-1,pY]

n = 1

elif p7 == choice:

choice = [pX-1,pY+1]

n = 1

elif p8 == choice:

choice = [pX,pY+1]

n = 1

else:

choice = [pX,pY]

n = 1

if n == 1:

listX.append(choice[0])

listY.append(choice[1])

pX = choice[0]

pY = choice[1]

n = 0

if pY == goal.Y and pX == goal.X:

whileloop = 'no'[/code:2buu5dmb]

Thanks for any help.