• 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!

Quick path question

Hi

If I want an object to move along a path, I start path_start in the scope of the object, right?
If that's true, then can I have multiple objects use a with and path_start to have multiple objects follow
a path?

For example,

Code:
draw_trail_of_bats--;

global.spacing_myTimer += 0.001;

if (global.spacing_myTimer > 1.0)
{
    global.spacing_myTimer = 1.0;
}

global.spacing_myTimer2 += 0.001;
if global.spacing_myTimer2 > 1.0
{
    global.spacing_myTimer2 = 1.0;
}
    

global.spacing_myTimer3 += 0.001;
if global.spacing_myTimer3 > 1.0
{
    global.spacing_myTimer3 = 1.0;
}
    

if (draw_trail_of_bats <= 0)
{
    //inst =
    //path from grasslands to forest?
    inst = instance_create(300, 371, SentryBatWalkMap);
    with (inst)
    {
        path_start(path19, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }

    draw_trail_of_bats = room_speed;
    
    //a path from forest to snow
    inst2 = instance_create(378, 354, SentryBatWalkMap);
    with (inst2)
    {
        path_start(path38, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer2));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer2;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
 
Ok. Update.

This is the travel code. It directs trails of minibats from one level spot to the next. Only thing is that its only showing one trail (one level to another).

So this is how the code is:
Code:
//path from grasslands to forest
if (global.completed_level1 == true && global.completed_level2 == false && inst != noone)
{
    //inst = instance_create_depth(path_get_point_x(path19, 0), path_get_point_y(path19, 0),-1000, SentryBatWalkMap);
    
    with (inst)
    {
        path_start(path19, 2, path_action_stop, true);
    }
}

///path from forest to snow
if (global.completed_level2 == true && global.completed_level3 == false && inst != noone)
{
    inst2 = instance_create_depth(path_get_point_x(path38, 0), path_get_point_y(path38, 0),-1000, SentryBatWalkMap);
    with (inst2)
    {
        path_start(path38, 2, path_action_stop, true);
    }
}

//snow to lava
if (global.completed_level3 == true && global.completed_level4 == false && inst != noone)
{
    inst3 = instance_create_depth(path_get_point_x(path44, 0), path_get_point_y(path44, 0),-1000, SentryBatWalkMap);
    with (inst3)
    {
        path_start(path44, 2, path_action_stop, true);
    }
}
Out of those three trails is only displaying one. I ran it through the debugger and it says for all of them the values that should be:


global.completed_level1 == 1 && global.completed_level2 == 0 for the first trail
then when you go on to the next level and finish it is
global.completed_level2 == 1 && global.completed_level3 == 0 for the second trail
and finally
global.completed_level3 == 1 && global.completed_level4 == 0 for the third trail
 
If I want an object to move along a path, I start path_start in the scope of the object, right?
Yes.

If that's true, then can I have multiple objects use a with and path_start to have multiple objects follow
a path?
Yes.

A path is simply a set of points. Any instance can follow any path. Multiple instances can follow the same path.

Out of those three trails is only displaying one. I ran it through the debugger and it says for all of them the values that should be:
I would start by putting some code to show the state of those variables on screen, so you can see their values in real time if you haven't already.

Create a new object called oDebug (or use an existing controller object if you have one already)

Draw GUI Event
Code:
draw_text(10, 10, "inst : " + string(inst));
draw_text(10, 30, "global.completed_level1 : " + string(global.completed_level1));
draw_text(10, 50, "inst2 : " + string(inst2));
draw_text(10, 70, "global.completed_level2 : " + string(global.completed_level2));
draw_text(10, 90, "inst3 : " + string(inst3));
draw_text(10, 100, "global.completed_level3 : " + string(global.completed_level3));
Does inst always exist?
In your second and third if() statements, you are still checking for if "inst" != noone. Should one or both of those be checking for "inst2" and "inst3" existing respectively?

Also, checking for inst != noone doesn't mean that the instance exists. A variable could still be holding the instance id of an instance that was destroyed. You might want to use if (instance_exists(inst) ) instead.
 
Ok. So, I changed things around and now I have some bats moving in the same place and another bat that's just static, not moving. Here is the trail code for the bats (that's the controller)

Code:
//path from grasslands to forest
if (global.completed_level1 == true)// && global.completed_level2 == false && inst != noone)
{
    inst = instance_create_depth(path_get_point_x(path19, 0), path_get_point_y(path19, 0),-1000, SentryBatWalkMap);
    
}

///path from forest to snow
if (global.completed_level12== true && global.completed_level3 == false)
{
    inst2 = instance_create_depth(path_get_point_x(path38, 0), path_get_point_y(path38, 0),-1000, SentryBatWalkMap2);
    
}

//snow to lava
if (global.completed_level3 == true && global.completed_level4 == false)
{
    inst3 = instance_create_depth(path_get_point_x(path44, 0), path_get_point_y(path44, 0),-1000, SentryBatWalkMap3);
    
}
And for each level there is supposed to be a trail of bats to it, and for each trail there is a mini-bat that makes up the trail. So I created three minibats. In the mini bats (SentryBatWalkMapx) there is a
check to see which levels are completed. So this is the first three trails: (draw events)

Code:
draw_self();
path_start(path19, 2, path_action_stop, true);

draw_self();
path_start(path38, 2, path_action_stop, true);

draw_self();
path_start(path44, 2, path_action_stop, true);
 

rIKmAN

Member
Code:
///path from forest to snow
if (global.completed_level12== true && global.completed_level3 == false)
{
    inst2 = instance_create_depth(path_get_point_x(path38, 0), path_get_point_y(path38, 0),-1000, SentryBatWalkMap2);
 
}
Code:
draw_self();
path_start(path19, 2, path_action_stop, true);

draw_self();
path_start(path38, 2, path_action_stop, true);

draw_self();
path_start(path44, 2, path_action_stop, true);
First thing I notice is that you are checking for global_completed_level12 in the above section, which I assume should be global_completed_Level2.

Second thing is that you are constantly restarting the paths by using path_start in the Draw Event which runs every frame, which would mean they never move along them the same way that alarms set in a Step Event never count down because they are getting reset every step.

I would also advise you start naming your paths with easily identifiable names to prevent confusion between them.
 
Ok rIKmAN welcome to the discussion.:) You were right, as usual, about the typo. And about the path_start in Draw event. So I've changed it to:

Code:
//path from grasslands to forest
if (global.completed_level1 == true && inst == noone)// && global.completed_level2 == false && inst != noone)
{
    inst = instance_create_depth(path_get_point_x(GrasslandsToForestTrail, 0), path_get_point_y(GrasslandsToForestTrail, 0),-1000, SentryBatWalkMap);
    
}

///path from forest to snow
if (global.completed_level2== true && global.completed_level3 == false && inst2 == noone)
{
    inst2 = instance_create_depth(path_get_point_x(ForestToSnowTrail, 0), path_get_point_y(ForestToSnowTrail, 0),-1000, SentryBatWalkMap2);
    
}

//snow to lava
if (global.completed_level3 == true && global.completed_level4 == false && inst3 == noone)
{
    inst3 = instance_create_depth(path_get_point_x(SnowToLavaTrail, 0), path_get_point_y(SnowToLavaTrail, 0),-1000, SentryBatWalkMap3);
    
}
Which makes the first trail work perfectly fine, however, it is doing what has been the problem from the beginning. It does the trail of bats for the first trail
(Grasslands to Forest)
//path from grasslands to forest
if (global.completed_level1 == true && inst == noone)// && global.completed_level2 == false && inst != noone)
{
inst = instance_create_depth(path_get_point_x(GrasslandsToForestTrail, 0), path_get_point_y(GrasslandsToForestTrail, 0),-1000, SentryBatWalkMap);

}
///path from forest to snow
if (global.completed_level2== true && global.completed_level3 == false && inst2 == noone)
{
inst2 = instance_create_depth(path_get_point_x(ForestToSnowTrail, 0), path_get_point_y(ForestToSnowTrail, 0),-1000, SentryBatWalkMap2);

}
//snow to lava
if (global.completed_level3 == true && global.completed_level4 == false && inst3 == noone)
{
inst3 = instance_create_depth(path_get_point_x(SnowToLavaTrail, 0), path_get_point_y(SnowToLavaTrail, 0),-1000, SentryBatWalkMap3);

} but doesn't do any of the other trails (such as Forest to Snow and Snow to Lava for example).

This is what the code for one of the trail bats looks like:

Code:
draw_self();
path_start(ForestToSnowTrail, 2, path_action_stop, true);
OH and the renaming the paths I never gave thought to that. Great idea. ;)
 
Renaming paths bad idea. The bats were going on a trail nicely like they were supposed to. Then suddenly stopped do ing that and I think the only thing could be is that I changed the name of the paths? So now I have no bat trails n ow.
 

Joe Ellis

Member
This isn't helpful to your immediate situation but I'd rather not use paths at all and make them with a list of points. There are several ways you can make a path yourself, like make an empty room with "obj_pathmaker". Create a path, save it to a file, then load it. It just avoids having to use the path functions and lets you deal with the coordinates however you want, as they're just in a list or array. But yeah this is just a side note, but something you might wanna look into if you don't like using paths
 
I do like the ease in creating a path, I'm just not liking it right now. So right now I have a a room, called VideoMap, and a controller TravelMaster. TravelMaster's job is to handle path_starts and other path related things. So I put a game map object (which is you guessed it, a map) into VideoMap. When I run the game and go to the map room, there is nothing. I even went as far as deleting VideoMap and creating a new blank VideoRoom and putting a new map into it and still all I get is the travelling mini-bats (controlled by the TravelMaster). In summary, its not drawing anything except what is controlled b y TravelMaster.
 

Joe Ellis

Member
Oh that sounds like something going wrong somewhere, like a single thing wrong in the code. Could you post the code?
It could also be problems with stuff happening between several instances, ones created before other ones
 
Oh that sounds like something going wrong somewhere, like a single thing wrong in the code. ICould you post the code?
It could also be problems with stuff happening between several instances, ones created before other ones
I've got it working. I'm not sure what had happened but
the background and the travelmaster are working now. I just deleted everything and rebuilt it. Which brings me back to the topic of this thread. The map (the travelmaster)
only shows the first trail of bats, even if I finished the third level and the fourth level is next, it still only shows the first trail, not the second to third trail or third to fourth trail.
 

Joe Ellis

Member
You might need to set something in the travelmaster when you change room. Which is hard if the travelmaster isn't persistent. Maybe set it to persistent. Then when you change room it'll still exist(won't get destroyed with everything else in the prev room)
But you have to make sure to not put it in every room, just the start room
 

rIKmAN

Member
This is what the code for one of the trail bats looks like:

Code:
draw_self();
path_start(ForestToSnowTrail, 2, path_action_stop, true);
The draw_self() above suggests this code is again in a Draw Event, which is what I explained in my previous post as the reason why things weren’t moving.
Renaming paths bad idea.
The bad idea was never naming them in the first place, would you go through a project using sprite89, sprite293 and sprite295 or is it infinitely easier if you renamed them spr_gun, spr_ball and spr_house?

The same logic applies to every resource, especially when so many of your problems are caused by typos and confusion with names.

When I suggested renaming them I didn’t just mean rename them in the Resource Tree, they are still being referenced in code by their old undescriptive names and is likely why they stopped working if all you did was rename them in the Resource Tree.

Do a global search and replace (CTRL+Shift+F) for the old names, pay attention to search the results (don’t blindly replace all) and replace each result that directly referenced the old name with the new name.
 
Last edited:
Ok. rIKmAN I moved the draw_self() into the draw event. (I need a draw_self() because the object, the min I bat that goes on the trail, needs to be visible - does that make sense?
No, I renamed in the code and the resource tree. Doing that, I thought messed things up but it turned out to be a different problem.
Yeah, I'm doing the global search thing, one by one for each path. But the original problem is still present. It only does the bail trail.

Bat Trail
A series of mini bats moving from one point (one level on the map) to another point (the next level in the game). All of this occurs
on the game map. The mini bats continuously move from the origin to the destination and vanish. This repeats for each trail.

(edit)

Is there any way to to create a point object individually like paths are made of. Basically I'm asking if you can do someth ing like:

instead of: inst2 = instance_create_depth(path_get_point_x(ForestToSnowTrail, 0), path_get_point_y(ForestToSnowTrail, 0),-1000, SentryBatWalkMap2);

do this:

inst2 = instance_create_depth(Point(200, 450), Point(654, 358),-1000, SentryBatWalkMap2);

I'm trying to figure out while this object (SentryBatWalkMap2) doesn't work
but (SentryBatWalkMap) works. Each instance_create_depth creates a SentryBatWalkMap object (or SentryBatWalkMap2 and so on named inst, inst2, inst3.... Then those SentryBatWalkMap in its create event has:

path_start(GrasslandsToForestTrail, 2, path_action_stop, true);

And SentryBatWalkMap in its create event has:

path_start(ForestToSnowTrail, 2, path_action_stop, true);

So it displays the first SentryBatWalkMap and it does that fine. Then it should display the second and third and so on..but doesn't.

 
Last edited:
Top