GML simple recursive problem in gml?!

Discussion in 'Programming' started by Kasra_n, Aug 2, 2019.

  1. Kasra_n

    Kasra_n Member

    Joined:
    Jun 19, 2019
    Posts:
    26
    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 :(
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,017
    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?
     
    Kasra_n likes this.
  3. Kasra_n

    Kasra_n Member

    Joined:
    Jun 19, 2019
    Posts:
    26
    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
     
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,955
    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.
     
  5. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    936
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice