Need help with looped functions

Get help using Construct 2

Post » Thu Mar 19, 2015 11:50 pm

Hello, I'm just trying to make some pathfinding system, and I've got a problem!

This is my function called "findpath". It does some actions and checkes if current array slot is finish point ( = "F" ). If its not ("ELSE"), then function must call itself and do this actions again and again, until it will get to the finish (there is always 100% way to reach finish point).

Image

But Im keep getting this error:
Image
Here is the line:
Image

Please, help!
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Fri Mar 20, 2015 12:33 am

Each time it is called in the "findpath" function, the for each XY element loops through the whole Path array. During that loop-through, every time the Else is triggered (which could be a lot, depending on how many "F" values it contains) it then calls the "findpath" function to run the for each XY element loop all over again... Which means it will run the for each XY loop as an infinitely self-triggering loop. I think... from looking at the event sheet.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,206
Reputation: 43,834

Post » Fri Mar 20, 2015 6:21 am

Colludium wrote:Each time it is called in the "findpath" function, the for each XY element loops through the whole Path array. During that loop-through, every time the Else is triggered (which could be a lot, depending on how many "F" values it contains) it then calls the "findpath" function to run the for each XY element loop all over again... Which means it will run the for each XY loop as an infinitely self-triggering loop. I think... from looking at the event sheet.


It contains 1 F value. There is no problem with XY loop, Im only getting error because of this else if I'm checking values in array's loop.
For example, I have my base code (which is working pretty well), and there is no problem.
Image
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Fri Mar 20, 2015 10:58 am

How do you know that line of code equates to the else condition? If you disable the else does the error still happen? I note that the other function calls also send parameters whereas the call after the else does not - perhaps that could be the source of the undefined error. Hard to say any more from the images.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,206
Reputation: 43,834


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, David181, fens and 8 guests