-
recursion
Hey. I'm trying to do some pathfinding with flash. I think i figured out a way to do pathfinding using recursive functions but the problem is flash will stop after 256 recursions, is there any way i can increase the maximum number of recursions?
Thanks
-
Untitled-1.fla
No, you cannot increase the maximum number of recursions. You could send in a depth variable and check that the recursion does not go beyond the limit. This will at least prevent the flash player from showing the message and disabling action script:
code:
recursive(1);
function recursive(depth) {
if (depth < 255) {
trace("depth: " + depth);
recursive(depth+1);
}
}
-
crap. acutally i need flash to go boyond that, it needs to do a maximum of 3600 recursions
damn i hate flash, it cant do anything good.
Thanks anyways
-
what do u need such a high number for? cant u do:
code:
while (i<60){
while (p<60){
//stuff
}
}
-
i need a high number for my path finding script, there are around 3600 tiles to search, so i need about 3600 recursions.
I'd use loops, but loops are alot slower than recursive functions
-
Yes we can
i´m sure you don´t have the whole map on the screen,so it´d be wiser not to search through the whole map but instead just the tiles on the current screen.
besides that you can use a method like strille suggested to check if you get close to the critical recursion level limit,if so you can stop the current recursive loop and start a sceond one.
i think you´re wanting to port a concept like A* for your pathfinder,aren´t you?
You shouldn´t use A* but a more simple pathfinder concept instead,it might not find the ideal way but it´ll be less processor intensive and will also run better in flash (especially when its about "realtime" pathfinding in action oriented game situastions.
).
I suggest you do a search on pathfinding,there are loads of threads on this topic.
-
Senior Member
Actually in Flash I believe recursion would be slower. Because in Flash it takes a long time to call a function, so I'm pretty sure a loop would be more efficient in that respect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|