2 Replies Latest reply on May 1, 2006 7:24 AM by skullnz

    Difficult class looping problem

      Apologies in advance, this is really complicated.

      Ok, so I'm having this inexplicable problem with a node-based pathing script I wrote. It's hard to explain, so follow closely and tell me if I'm making no sense. I'm thinking that this is a design limitation in Flash, or a bug. I need to know if it's either so I can move on from this issue or solve it as needs be.

      The script starts knowing both its start and end nodes. Each node has a list of which nodes it connects to. The basic premise of the script is to trace out all possible paths and choose the shortest one.

      Each node is an instance of the class called "node". When the search runs, each node runs a search_nodes() function which in turn asks each connected node to run the same function. It does this until it finds the destination node.

      The script correctly handles dead ends and very-long-paths, so don't worry about that.

      The nodes DO form loops, so each node has a list of every node that preceeded it in that particular trace. If one of the child nodes to be searched appears in the previously-searched list then it stops that particular trace as it's clearly a loop, which we don't want.

      Now, here's whats going wrong:
      Pretend node 12 is a junction that leads to several other nodes. Node 12 traces out its path along one child and finds a solution. Now it's time to trace the OTHER path from node 12 to see if that path is shorter.

      Unfortunately, between child 1 and child 2 the supposedly unchanging previous-node-list inside node 12 has picked up every single node from the child 1 trace!

      Therefore if node 12 began with a previous-node-list that goes "node 11, node 9". It's child has a list that goes "node 11, node 9, node 12" and so on. Somehow, some way, when child 2 begins its run node 12's previous-node-list has changed and now includes the entire path that child 1 found.

      I think what's happening is child 1 eventually reaches node 12 AGAIN (call it node-12-instance-2) as part of a loop and that particular child of child 1 is killed. It then goes on to find the destination, but now node-12-instance-1 has all the attributes of node-12-instance-2. As a result node 12 stops tracing its children because now they're registering incorrectly as loops.

      The damn pathing system works beautifully apart from the single fact that it only ever chooses the first-found path.

      To summarise the problem:

      Two instances of the same class are sharing properties, and they shouldn't be. This may be because the node re-includes itself deep inside a hierachy while the original node is still executing the function that eventually lead to node-12-instance-2 being called.


      I've tried making each child a new instance of a new movieclip-less class in the hope that would help, but no go. Has anyone encountered this? Does anyone have a clue whats going on?