GML simple recursive problem in gml?!

K

Kasra_n

Guest
how can i implement a code like this in gml ?
Code:
void inOrder(int x){
    inOrder(leftChild[x]);
    queue.push_back(x);
    inOrder(rightChild[x]);
    return;
}
it is on c++ and works fine, but i tryed:
Code:
//script find_patch
var xc = argument[0]; // xcx starts by 0
if (xc < 10)
for(var i = 0; i < 10; i++)
{
    find_patch(xc+1);
}
else return false;
and not working :(
 

samspade

Member
It seems like it will work just fine but do nothing other than increment a local variable and eventually return false in some cases. What it is supposed to do? Have you stepped through it with the debugger yet?
 
K

Kasra_n

Guest
It seems like it will work just fine but do nothing other than increment a local variable and eventually return false in some cases. What it is supposed to do? Have you stepped through it with the debugger yet?
yes, i do, actually this code is just an example, my main code is a crap algorithm that i invented for patchfinding, and yes as you said recursive with void value will work in gml as well, i just had bunch of complicated logic errors in my main code, i just wanted to make sure about recursive in gml
 

NightFrost

Member
I don't know c++ so I've no idea what that code would do, but the GML code seems to be a massive loop. As far as I can tell, it will first recurse up to value "9," then call the recursion ten times with a value of "10." After that it drops down one recurse level to second "9", and calls itself with "10" ten times again. This happens ten times, and then the recurse level drops down to second "8", which calls with "9" ten times, which all call with "10" ten times, until "8" has been handled ten times. Then it drops in recurse level to second "7" and calls itself with "8" ten times, which all call itself with "9" ten times, which all call itself with "10" ten times... you see where this is going.
 

Joe Ellis

Member
The problem is your not affecting xc at all in the for loop, the i variable is meant to be used inside the for loop, so it should be used instead of xc.
It looks like this loop will just ask the same thing 10 times cus xc never moves on
 
Top