problem with pathfinding

hi i have implemented the A* pathfinding but it wont work in game… only in blender… and the console is saying that the “GameLogic” has no module “nodes”.

do anybody here know how to fix it?

and i’m using script from this thread: http://blenderartists.org/forum/showthread.php?t=174092&highlight=pathfinding

here’s the blend… http://db.tt/9ZgAMJj

If I try to run this as a runtime, I get the same error.
The problem is this piece of code:

if gl.nodes and gl.Done == 0

The person who made this stored the varialbes “nodes” and “Done” in gl(GameLogic-module).
I think in runtimes you can’t store variables in the GameLogic module.

so you think if i set these things to another variables it will work?

the problem is

import Blender

(line 38 of Generate)

as this module is not available at runtime the script fails and does not add the attribute node at line 61.

Redesign the script to avoid Blender and it will run.

I think you need this!

heh i was trying but i’m not so good in python :smiley: so i!m stuck with it now…

click on kx_mesh_proxy it contains an example

Hey.

I think I fixed the problem.

replace Generate with this:

###
gl = GameLogic
cont = gl.getCurrentController()
own = cont.owner

pos = own.position
objName = own.name[2:]

nodes = {}
nodelist = []

###
print """
__________
Generating
"""


###
class node:
    def __init__(self,name,list,pos,next=[]):
        self.name = name
        self.pos = pos
        self.next = next
        list[name] = self


def strf(f):
    return str(int(f*10))


def namepoint(v):
    name = strf(v.getXYZ()[0])+","+strf(v.getXYZ()[1])+","+strf(v.getXYZ()[2])
    return name




###
def trpoint(point,offset=pos):
    return [point[0]-offset[0],point[1]-offset[1],point[2]-offset[2]]

mesh = own.getMesh(0)


###
for mat in range(mesh.getNumMaterials()):
    for v_index in range(mesh.getVertexArrayLength(mat)):
        vertex = mesh.getVertex(mat, v_index)
        
        name = namepoint(vertex)
        
        if not name in nodes.keys():
            nodes[name] = node(name,nodes,trpoint(vertex.getXYZ()))
    
            nodes[name].next = []
            
        for v_index2 in range(mesh.getVertexArrayLength(mat)):
            v2 = mesh.getVertex(mat, v_index2)    
            
            if name != namepoint(v2) and namepoint(v2) not in nodes[name].next:
                nodes[name].next.append(namepoint(v2))
        
            
            
gl.nodes = nodes
#print nodes

### Done ###
print """
Finished!!
__________
"""

now it’s working but the AI dont go to the its closest point. it will go to the your closest point… so the cone will always appear near you and the Ai have to follow it even through walls… but it is the step forward…