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

Strange path problem

rIKmAN

Member
I've been chasing what I thought was a bug in my code for a few evenings, and finally managed to nail it down to an issue with path_start not initialising related variables (like path_position) for a couple of steps after it is called.

I've boiled it down to this simple example.

Create a path, and then start it in a Create Event:
Code:
path_start(pathPatrol, 0.5, path_action_restart, true)
Then in the Step Event:
Code:
if(keyboard_check(vk_space))
{
   path_speed = 0.5;
}
else
{
   path_speed = 0.0;
}
Logging path_speed shows the correct values, however path_position always returns -1 and there is no movement of the instance when space is held down, it just remains static with a -1 path_position.

If I switch those values around things work as expected and the instance stops when space is held down and moves when it's released.

I then found that if I set an alarm for 2 steps in the Create Event and set a flag to true, and then wrap that keyboard check inside an if check for that flag being true, it then all works as expected.
(You can also use your own counter instead of an alarm of course, same result.)

So it seems like path_start is taking 2 steps to initialise, similar to how you can't use window_center until the frame after you change the window size, and when I set path_speed to 0 straight away it never gets chance to properly initialise and never starts.

I also noticed that if I set the initial speed in path_start to 0, then even using the 2 step delay doesn't work and the instance doesn't move at all - again with path_position returning a constant -1.

Can anyone confirm or have any ideas on what might be going on?

I was going to report it as a bug but was asked to post here first to see if anyone more familiar with paths could give any insight in case it's expected behaviour but undocumented or my understanding of what I expect to happen is off.

Thanks.
 

rIKmAN

Member
Hi,
Maybe you're looking for keyboard_check_pressed instead of keyboard_check?
keyboard_check_pressed only returns true in the frame it is pressed which means it would only move for a single frame.
Changing "path_action_restart" to "path_action_stop" should solve your problem.
Just tried this and you are right, that has fixed the issue!

Any idea why that's the only one that works?
Some extra calculations with the other endaction types maybe?
 
keyboard_check_pressed only returns true in the frame it is pressed which means it would only move for a single frame.

Just tried this and you are right, that has fixed the issue!

Any idea why?
*shrugs* I would like to know as well. Either thats a problem with path_action_restart, or i am misunderstanding how paths work.
 

rIKmAN

Member
*shrugs* I would like to know as well. Either thats a problem with path_action_restart, or i am misunderstanding how paths work.
Oh so you've had the same problem?
I thought you had some inside knowledge the way you answered so matter of factly and were spot on haha.

I tried all the endaction types and the only one that worked was path_action_stop, so I don't think it's specific to path_action_restart.
 
Oh so you've had the same problem?
I thought you had some inside knowledge the way you answered so matter of factly and were spot on haha.

I tried all the endaction types and the only one that worked was path_action_stop, so I don't think it's specific to path_action_restart.
I just tested your code myself and thats how i got it working :)
 
Top