GMS 2 [SOLVED] How to truely STOP a path

hughrock18

Member
Hello everyone. I appreciate you coming in to check on this thread.

I've been working with GMS1.4 for the longest time, and now GMS2 (for a total of roughly 5 years of working with gamemaker as a whole). In all this time, I've ALWAYS written my own movement code. I've never, once, used the path functions, but had a basic understanding of their operation.

Now, I'm dabbling in paths (more for a complete understanding of the IDE and its intricacies).

My main issue atm is what to do when an instance has completed its path. I check "path_position == 1" to see if an instance is at the end of the path (NOTE: path_endaction = path_action_stop). The if statement returns true and runs code, but it runs the code every step, relentlessly (and i DO mean relentlessly). I can't seem to stop the code from running without starting a new path, moving the instance to a new position along the path (that isn't "1" obviously), or destroying the instance running the path.

My needs are simple. When the instance reaches the end of the path, I want it to stop. I mean not just stop moving on-screen, but i want the path to finish, run a code block, and "vanish".

The "vanish" part is where I'm stuck. The path is still assigned to the instance and therefor constantly registers the instance being at the end of that path. I want the instance to return to the "state" BEFORE assigning it the path (so it would have NO path attached to it).

I feel like there would be some sort of "path_UNassign" function. Surely, i'm missing something.

Any help would be greatly appreciated.

Thank you.
 

SeraphSword

Member
As far as relentless checking, why not just use a variable like shouldCheck = true, then at the end of you path set shouldCheck = false. So in your Step event, you use an if (shouldCheck == true), where the variable is set to true in the same spot you start the path. That way you are only checking when you have something to check.
 

jo-thijs

Member
Hello everyone. I appreciate you coming in to check on this thread.

I've been working with GMS1.4 for the longest time, and now GMS2 (for a total of roughly 5 years of working with gamemaker as a whole). In all this time, I've ALWAYS written my own movement code. I've never, once, used the path functions, but had a basic understanding of their operation.

Now, I'm dabbling in paths (more for a complete understanding of the IDE and its intricacies).

My main issue atm is what to do when an instance has completed its path. I check "path_position == 1" to see if an instance is at the end of the path (NOTE: path_endaction = path_action_stop). The if statement returns true and runs code, but it runs the code every step, relentlessly (and i DO mean relentlessly). I can't seem to stop the code from running without starting a new path, moving the instance to a new position along the path (that isn't "1" obviously), or destroying the instance running the path.

My needs are simple. When the instance reaches the end of the path, I want it to stop. I mean not just stop moving on-screen, but i want the path to finish, run a code block, and "vanish".

The "vanish" part is where I'm stuck. The path is still assigned to the instance and therefor constantly registers the instance being at the end of that path. I want the instance to return to the "state" BEFORE assigning it the path (so it would have NO path attached to it).

I feel like there would be some sort of "path_UNassign" function. Surely, i'm missing something.

Any help would be greatly appreciated.

Thank you.
GameMaker keeps track of the current path the instance is following in the variable path_index.
If path_index is -1, the instance is following no path.
Otherwise, if path_index is the index of a path, then the instance is following that path.

By setting path_index to -1, you make the path "vanish".

The "path_endaction = path_action_stop" should already reset path_index to -1 when the path ends, but it doesn't reset path_position.
Simply resetting path_position to 0 once path_index >= 1 worked for me to make the if-block only run once when I just tested it in GameMaker 1.4.

As far as relentless checking, why not just use a variable like shouldCheck = true, then at the end of you path set shouldCheck = false. So in your Step event, you use an if (shouldCheck == true), where the variable is set to true in the same spot you start the path. That way you are only checking when you have something to check.
This is also a good option, although it should be unnecessary in this particular case.
 

hughrock18

Member
As far as relentless checking, why not just use a variable like shouldCheck = true, then at the end of you path set shouldCheck = false. So in your Step event, you use an if (shouldCheck == true), where the variable is set to true in the same spot you start the path. That way you are only checking when you have something to check.
I actually have been using that method to ensure it doesn't check more than once at a time, but my issue isn't just making the sprite stop along the path and run code. The path is somehow attached (indexed?) to the instance (in this case the player object) once the "path_start" function is called, but I want remove that path from the instance.

In your example the path isn't removed from the instance. Rather, it's still very much there and constantly telling the game that the player is at the end of the path until I assign it a new path (or destroy the instance).
 

hughrock18

Member
By setting path_index to -1, you make the path "vanish".
Thank you! I KNEW it would be something simple. I should've guessed that. It works the same for sprite_index (and most "_index" vars).

EDIT: Unfortunately, while it may let you set the path_index, gms2 treats it as read-only. However, i was able to make it work with this:
Code:
// Step Event

if( path_position == 1 )
{
   path_position = 0;
   // run code
}
It works because the path_index is set to -1 by GM at the same time the position reaches "1" (end of the path).
 
Last edited:

SeraphSword

Member
GameMaker keeps track of the current path the instance is following in the variable path_index.
If path_index is -1, the instance is following no path.
Otherwise, if path_index is the index of a path, then the instance is following that path.

By setting path_index to -1, you make the path "vanish".

The "path_endaction = path_action_stop" should already reset path_index to -1 when the path ends, but it doesn't reset path_position.
Simply resetting path_position to 0 once path_index >= 1 worked for me to make the if-block only run once when I just tested it in GameMaker 1.4.


This is also a good option, although it should be unnecessary in this particular case.
Isn't path_index "read only"? That's what it says in the documentation, so I wasn't sure if you could set it manually (which was going to be my other suggestion).
 
Top