• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED] What might be causing mp_grid_path to fail?

T

Tset_Tsyung

Guest
Hey all,

Title says it all really.
I have a character that follows sounds (or the player if he sees them). After reaching the end of their 'investigation' they will wait 6 seconds and then return. However the mp_grid_path call keeps failing, and the character is not returning to their original position.

What sorts of things should I be checking to see if they are the problem?

Many thanks in advance!

Mike
 
T

Tset_Tsyung

Guest
Hi @Alexx,

Many thanks for the reply. Here's the first bit of code from the step event of 'patroling teacher' object - please note that this is the part that gets fired when they reach the end of their investigation path. I'm using a large if/else if statement to handle the AI states (total noob so not sure if that's what's best...).

Code:
else if(ourstate == teacherState.investigating && path_position == 1)
{
    // we've reached the end of our investigation path, so wait to return;
    show_debug_message("We've reached the end of our investigation path.  Now waiting 6 seconds");
    ourpreviousstate = ourstate;
    ourstate = teacherState.waiting;
    path_delete(ourpath);
        
    ourpath = path_add();
    alarm[0] = 6 * room_speed;

} else
This next part is from the alarm section that get's fired after 6 seconds.

Code:
 else if (ourpreviousstate == teacherState.investigating)
{
    //if(!path_exists(ourpath))
    //    ourpath = path_add();
        
    // Here we should check for the closest point of the path and return there.
    // Or return to the start of the last route (reversed or not).
    
    show_debug_message("We're in the timed section after investigating. routeposition = " + string(routeposition));
    
    returnx = path_get_x(ourpatrol,routeposition);
    returny = path_get_y(ourpatrol,routeposition);

    if(path_exists(ourpath))
        show_debug_message("There is a path to be set");   
    
    show_debug_message("We're going to try and set a return path");
    if(mp_grid_path(global.ourgrid,ourpath,x,y,returnx,returny,true))
    {
        path_start(ourpath,1.5,path_action_stop,true);
        show_debug_message("We're returning to our patrol");
        ourstate = teacherState.returningToPatrol;
        ourpreviousstate = teacherState.waiting;
    } else {
        show_debug_message("Failed to set return path");
    }

} else
The debug output reads as follows:
We've reached the end of our investigation path. Now waiting 6 seconds
We're in the timed section after investigating. routeposition = [whatever it is at the time]
There is a path to be set
Failed to set return path

As you can see, I've experimented with placing path_add() in various places, but this doesn't change the outcome - it was a shot in the dark.
I've called it a night for today. Tomorrow I'll see if there was a problem with the return coords.
 
T

Tset_Tsyung

Guest
FOR THE LOVE OF SANITY!

Solved it... man I'm gonna go and kick myself after writing this.

Basically, in the timed event I set the 'returnx' and 'returny' variables to where we were on our patrol route. The thing is that when I instantiated the object I set their patrol up with ourpath NOT the ourpatrol path variable. I use different paths for storing our patrol so that the object can easily return to it... I just forgot my own procedure for instantiating the object...

Sorry to have wasted your time all :(

Have a great weekend!

P.S. Did I say that I was a noob?
 
Top