Circumventing the Pathfinding bug
Hi there,
I'm making a turn-based strategy game, and am using the Pathfinding object just fine. However, I've run up against the bug that other people have noticed before - namely, when it can't find a path, it crashes the application.
I've attached a screenshot of my problem:
http://nzphoenix.com/imagebin/game-example.jpg
What I want to have happen is to get rid of the blue movement squares that are on the other side of the barrier - they ought to be inacessible, but I'm not sure how to go about reliably destroying them. I would have checked whether a path could be found to them, but of course that's where the bug comes in to play.
So does anyone know of any alternatives I could try to get rid of inacessible movement squares? Any help would be really appreciated.
Cheers.
Re: Circumventing the Pathfinding bug
I check to see if a square is inaccessible using the overlay object. Every square is represented by 1 pixel, and I use loops do a flood fill on the source square/pixel and check to see if it has changed the colour of the potential destination square/pixel. Might not be the most efficient method, but it works.
Re: Circumventing the Pathfinding bug
Ah, cool, thanks for that, I'll give it a go!
Re: Circumventing the Pathfinding bug
This may seem quite unrelated, but I'm just trying a different way of doing things, and was wondering if anyone knew of a simple way to detect exactly how many of a single object is currently overlapping a different object.
So for example, if you have three A, and they are all overlapping B, how could you get MMF to detect that three of them are overlapping?
Thanks!
Re: Circumventing the Pathfinding bug
You can use the select object to retrieve how many objects matched the conditions.
The following code would count how many A's were overlapping any B's:
[events]
*A is overlapping B
-Set counter to (Select Object) number of 'A' that matched conditions.
[/events]
So if you had 10 A's and 10 B's and 3 A's were overlapping one B and 2 more were overlapping another it would put 5 in the counter.
To get how many B's were overlapping each A you would need a loop, like this:
[events]
*Always
-Spread Value 0 in Alt Z of 'A'
*Always
-Start Loop "Overlap"
*On Loop "Overlap"
+Alt Z of 'A' = loop index("Overlap")
+B is overlapping A
-Set Alt A of 'A' to (Select Object) number of 'B' that matched conditions.
[/events]