GMS 2 [SOLVED] Possible bug in mp_linear_path_object()

Discussion in 'Programming' started by Satori, Dec 1, 2018.

  1. Satori

    Satori Member

    Joined:
    Oct 26, 2018
    Posts:
    33
    My top-down game uses procedurally generated levels, and I use the function mp_linear_path_object() after the map is completed to make sure there is a clear path to the exit. In theory, this function should return true if a path is found and false if it isn't. My problem is that in rare instances the function will return true even if the path is completely blocked.

    Here is the code I use in a user event of obj_player:
    Code:
    if !mp_linear_path_object(path0, global.strdn.x+64, global.strdn.y+260, 2000, obj_wallblock)
    {
        global.flrseeds[global.flr] = 0; // Erase random seed
        room_restart();
    }
    
    This checks for a path between the player's starting location and a spot just in front of the stairs. If the path is blocked, it erases the random seed for the level and starts over. But as I said, sometimes it returns true even when the path is blocked.

    Am I doing something wrong, or is this a bug in the function? Is there a better way to do this?
     
  2. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,824
    stepsize of 2000!!! you are telling it your instance is moving at speed of 2000 pixels per step
     
  3. Satori

    Satori Member

    Joined:
    Oct 26, 2018
    Posts:
    33
    Yes, I know, but the instance isn't really moving, it's only checking to see if a path exists. The actual path is never executed. I've tried using smaller numbers, but then it takes longer to calculate and sometimes it returns false when a path does exist (the opposite of my current problem). The room size is 5760 x 5760, which is why I used such a large number.
     
  4. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,824
    you may have better luck with
    mp_grid_path

    grid cell size of 32x32 should be cost effective on a room that size
     
  5. Satori

    Satori Member

    Joined:
    Oct 26, 2018
    Posts:
    33
    Thanks for the suggestion. I've never used any mp_grid functions before, so I'll have to research that. Looks like there's a bit more setup involved, but I'll check it out when I have more time.
     
  6. Satori

    Satori Member

    Joined:
    Oct 26, 2018
    Posts:
    33
    mp_grid_path seems to be working perfectly. Thanks for your help!
     
  7. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,824
    if you have a version of the dysfunctional project that is easy to understand, you should probably report this to yoyo, It feels like a bug to me...
     

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