[Solved] LinearPath trouble


(HeraldR) #1

1.I’m having two problems right now. The first one is that LinearPath isn’t calling the completion function. This is the enemy class with the problem: http://pastebin.com/g814UGEf (I couldn’t get the inline code pasting to work)

I want the function newPath to be called once the entity reaches the destination. I could just do if (currentPath.complete == 1) { newPath(); } but I feel like I should be able to get this callback function to work.

2.[Solved]The second problem I have, which isn’t as big of a deal, is with my aStar function. I followed the policy almanac tutorial yesterday, and implemented the pathfinding for my entities, but for some reason the entities seem to stop one short on the grid. I’m thinking it might be caused by the origin being the top left of the entity, in which case I’m fine with it. If it’s caused by some other error in a loop somewhere I’d love to find it. Here is the aStar function: http://pastebin.com/WZvQhEXH

update: I figured out my second problem. It was an off by one error. Line 86 of the aStar algorithm should read: for (var j:int = currentPath.pointCount - 1; j > -1; j--) update2: Check my post below for the solution to my first problem. I was creating a new Tween with a callback function and then assigning it another tween that did not have a callback function set.


(Jonathan Stoler) #2

Here’s my guess (I haven’t actually run your code to see what’s actually happening):

Your update() function is empty, so your Entity isn’t updating and therefore the tween isn’t updating and so it isn’t detecting whether or not it’s completed yet.

You also have a super.update() in your added() function. I think you might want super.added() or (more likely) to move this to your update() function.

Since your update() function is empty, you could just remove it entirely, but I’m guessing you’ll want to add to it later.


(HeraldR) #3

Ah! Thanks for the catching the part about the super.update() in the added function. I tend to call the super function at the beginning of functions I overwrite even when it’s wrong to do it and it gets me into trouble. Basically cargo cult programming. I just went through my program and I did a call to super.update() in my game world’s begin() function!

Coming back to the problem after a long break it occurred to me what might be happening. I’m saying on line 42 and 43: var currentPath:LinearPath = new LinearPath(newPath); currentPath = pathfinderAStar.findPath(x, y, targetBall.x, targetBall.y);

The problem is that I’m initializing a new LinearPath with a callback function (newPath) in one line, and then in the next line I’m assigning it a new linearPath that doesn’t have a callback fuction. I did think of this earlier today but when I tried to assign currentPath.complete = newPath(); it didn’t work so I gave up on that and tried modifying the findPath function to return a LinearPath that had a blank callback fuction named newPath. That didn’t give me any errors but it also didn’t call the callback function.

If I hadn’t given up so early on assigning the complete function (and if I hadn’t been so frustrated in general, at that point I was really flailing around blindly in the code) I would have fixed it. It should be currentPath.complete = newPath;. The same syntax of the function name without parentheses as is used when declaring a new LinearPath. So add the line right after 42 and 43: var currentPath:LinearPath = new LinearPath(newPath); currentPath = pathfinderAStar.findPath(x, y, targetBall.x, targetBall.y); currentPath.complete = newPath;