1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Old Code Help - Solved

Discussion in 'Programming' started by ColonelMustache, Sep 24, 2019.

  1. ColonelMustache

    ColonelMustache Member

    Joined:
    Sep 24, 2019
    Posts:
    3
    Hi
    I've haven't used game maker in a lot of years but recently decided to pick up an old project of mine when I was using Game Maker 8. I'm trying to use a node based pathfinding system from the legacy forums called Gm Node Pathfinding Dll by icuurd12b42. Unfortunately he seems to have left the forums. I figured most of the people here have switched to studio but I'm pretty sure the problem isn't anything to do with the dll, but something stupid I'm forgetting to do. Basically there is a script called NodePathCreate that pretty much works like mp_grid_path. Ive used it and it does create a perfect path through the nodes I've put down. After that there is a script to translate it to a gm path which is where I'm stuck. Basically it wont create a gm path. Here is my code for trying to create the path. It's in a left released event.

    with (global.selectedunit)
    {
    nodepath=NodePathCreate(currentnode,global.region.mainnode,0,0,0,0)
    if nodepath>=0 {FillGMPath(nodepath,realpath,0,currentnode.x,currentnode.y)}
    if realpath>0 {path_start(realpath,2,0,0)}
    }

    nodepath does come up with a nice path but realpath never gets filled with anything. Is there anything wrong with this code?

    Global.selectedunit is just a basic object with a create event of:

    image_index=0
    image_speed=0
    currentnode=instance_nearest(x,y,NodeObj)
    currentregion=instance_position(x,y,o_Regions);
    realpath=-1
    nodepath=-1

    Somehow I think its something really basic that I'm forgetting. Any ideas?

    Thanks
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,389
    At a guess - you need to assign an empty path to the realpath variable first before you call FillGMPath().

    If you are not doing so already, put this line somewhere before you call the code you posted above:

    Code:
    realpath = path_add();
    
    Bear in mind - you will have to manage the deletion of this path yourself when you no longer need it - or else you will get a memory leak.
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,095
    Well, that's just a code fragment that calls for scripts where the real action happens. But going by your description, the problem is somewhere in FillGMPath, which is failing to turn the information returned by NodePathCreate (which you say is working perfectly) into a path that can by used by GML.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    Are you on GMS1.4 or GMS2? The format might've changed between GM8 and GMS2 (or rather GMS1 --> GMS2) since you can do more things with paths now and paths can also be created inline in rooms.

    Also, if you can see the node path in GM, could you manually loop through it and use the function to add a point to a path dynamically to build the path that way instead of using the DLL?
     
  5. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,095
    By the description, I'm pretty sure the dll performs the A* pathfind via the first script call, and the second script is what's supposed to do that, construct a GML path from the returned node list.
     
  6. ColonelMustache

    ColonelMustache Member

    Joined:
    Sep 24, 2019
    Posts:
    3
    Hey guys
    Thanks for all the responses. IndianaBones got it right! I just needed to add path_add(). For some reason I took it for granted that the dll would create the path and fill my empty variable with it, but I was wrong. I knew it was going to be something simple I was missing. Thanks everyone!
     
    IndianaBones and ParodyKnaveBob like this.
  7. ParodyKnaveBob

    ParodyKnaveBob The Laughing Rogue

    Joined:
    Jun 23, 2016
    Posts:
    537
    Howdy, ColonelMustardche, and welcome to the GMC. $:^ J

    I'm glad all is well now. I write, however, for three little bits of forum help:
    1. Now that this thread is solved, go ahead and edit your first post to add "solved" to the title, yay. $:^ ]
    2. When writing code on the forum, you can wrap it in [code]these little code block thingies[/code] to keep your indentation lookin' sharp.
    3. Oh ho, @icuurd12b42 does still haunt these halls. $;^ }
    Regards,
     
  8. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,840
    Booh!

    I do believe FillGMPath is a dll function call that was able to directly call gm8/7 path_add_point() from inside the dll...

    You will have to write that yourself (in gml). And I dont remember much about that dll
     
    ParodyKnaveBob likes this.

Share This Page