Path-Chaos: One character, different pathes/room - goes wrong!

Hi guys.

I´ve remarked it at different sites of my game:
Some of my created enemies (manually droped down to patrolling-pathes, each one has its own path)
seem to reappear in another rooms. I used one sprite (object) for several needs (different pathes in
different rooms).

For example I gave a rusty knight (put into different rooms) that code-fragment:

Code:
if (Path_C1LV02_Warrior_s1){
    path_start(Path_C1LV02_Warrior_s1, 4, path_action_continue, true);
}
{
if (Path_C1LV03_Warrior_s1){
    path_start(Path_C1LV03_Warrior_s1, 4, path_action_continue, true);
    }
}
Now... as you can see, the warrior got in two rooms his own, different-named path specifications.
The current result is:

The warrior in Level 2 behaves like the one in Level 3, off his given path, I considered
for him. Can somebody show me my mind-error, which keeps me away from solving that?
How can one character act correctly on each different path/level?

Thank you.
Archie.
 
I'm not quite sure how paths are treated in different rooms. I would have suggested using "if path_exists", though am unsure if that just goes on whether the path exists in the project - or if it is in a particular room.

Maybe in the object you could do something that checks which room it is in? And then use that to decide the path it starts.

Code:
switch (room)
{
case 1: path_start(Path_C1LV02_Warrior_s1, 4, path_action_continue, true) ; break;
case 2: path_start(Path_C1LV03_Warrior_s1, 4, path_action_continue, true);  break;
etc
etc
}
Or in the objects create event:

Code:
switch (room)
{
case 1: is_path =  Path_C1LV02_Warrior_s1; break;
case 2: is_path =  Path_C1LV03_Warrior_s1;  break;
etc
etc
}
And then reference 'is_path' later on when you want it to start patrolling.

Code:
path_start(is_path, 4, path_action_continue, true) ;
That way it is permanently held, so if it leaves the path and then goes back to patrolling, you don't need to look up again what path it should be using.
 

TheouAegis

Member
if (Path_C1LV02_Warrior_s1){
Put into English just what exactly you are trying to say in this line here. Because no, what you read in that line is NOT what you are trying to say.

What that line actually says is, "If the ID of Path_C1LV02_Warrior_s1 has a value of 1 or higher..." Which in turn means if the path does not exist, you'll get an unknown variable error, and if the path is at the top of the resource tree, it will have an ID of 0 and thus that condition will be false.
 
I'm not quite sure how paths are treated in different rooms. I would have suggested using "if path_exists", though am unsure if that just goes on whether the path exists in the project - or if it is in a particular room.

Maybe in the object you could do something that checks which room it is in? And then use that to decide the path it starts.

Code:
switch (room)
{
case 1: path_start(Path_C1LV02_Warrior_s1, 4, path_action_continue, true) ; break;
case 2: path_start(Path_C1LV03_Warrior_s1, 4, path_action_continue, true);  break;
etc
etc
}
Or in the objects create event:

Code:
switch (room)
{
case 1: is_path =  Path_C1LV02_Warrior_s1; break;
case 2: is_path =  Path_C1LV03_Warrior_s1;  break;
etc
etc
}
And then reference 'is_path' later on when you want it to start patrolling.

Code:
path_start(is_path, 4, path_action_continue, true) ;
That way it is permanently held, so if it leaves the path and then goes back to patrolling, you don't need to look up again what path it should be using.
Thank you, I will try that. :)

uhm...

I'm not quite sure how paths are treated in different rooms. I would have suggested using "if path_exists", though am unsure if that just goes on whether the path exists in the project - or if it is in a particular room.

Maybe in the object you could do something that checks which room it is in? And then use that to decide the path it starts.

Code:
switch (room)
{
case 1: path_start(Path_C1LV02_Warrior_s1, 4, path_action_continue, true) ; break;
case 2: path_start(Path_C1LV03_Warrior_s1, 4, path_action_continue, true);  break;
etc
etc
}
Or in the objects create event:

Code:
switch (room)
{
case 1: is_path =  Path_C1LV02_Warrior_s1; break;
case 2: is_path =  Path_C1LV03_Warrior_s1;  break;
etc
etc
}
And then reference 'is_path' later on when you want it to start patrolling.

Code:
path_start(is_path, 4, path_action_continue, true) ;
That way it is permanently held, so if it leaves t
he path and then goes back to patrolling, you don't need to look up again what path it should be using.
Hi.

I tried your first suggestion, because the others do not work. The first way has one problem:
The enemies animate, but they don`t follow their pathes. :-(

Greetings, Archie.
 
Last edited by a moderator:
Yo.

I figured out another way (to the create event of the concerning object (enemy)):

Code:
if room = LV_02 { path_start(Path_Level2_Warrior1, 4, path_action_continue, true);}
if room = LV_03 { path_start(Path_Level3_Warrior1, 4, path_action_continue, true);}
Well... I guess, there are another, more elegant ways to solve... but it works. :)
Thanks!

Archie.
 
Last edited:
My suggestion didn't work because I had to make assumptions about what your paths are called, and also used basic examples for what the rooms might be called - since I don't know that either.

Having made a project to test this, I can say it does work and will use specific examples this time.....This is exactly as I named them in my project - you will need to change this to reflect your names

Two rooms:
room0;
room1;

Two paths:
path0;
path1;

create event of object 'soldier'
Code:
switch (room)
{case room0: is_path = path0; break;
case room1: is_path = path1; break;}
An instance of 'Soldier' was placed in each room.

Global mouse button right released event in 'Soldier'
Code:
if room == room0
{room_goto_next();}
else
{room_goto(room_first);}
Global mouse button left released event in 'Soldier'
Code:
path_start(is_path, 4, path_action_continue, true) ;
What this does: Every press of the right mouse button switches between the two rooms. Every press of the left mouse button starts 'Soldier' moving down the path. What that path is, is defined in it's create event and taken from what room it is in. You can ignore the mouse button things, as they were only there for the purposes of testing.

I had two different paths, and saw it moving along a different path based on what room it was.

The reason this works is because path start is only being called once - only when the left mouse button is pressed. The same goes for having path start in the create event - it is only called once.

If you have path start in a step event it will be called repeatedly, and so the instance will constantly go back to the beginning of the path. When that happens it will appear to not be moving - because it isn't, as it's being told each step to go to the beginning of the path. It has no understanding of already being on a path, and will take that command very literally.

Hopefully that clears up a few things for you.
 
My suggestion didn't work because I had to make assumptions about what your paths are called, and also used basic examples for what the rooms might be called - since I don't know that either.

Having made a project to test this, I can say it does work and will use specific examples this time.....This is exactly as I named them in my project - you will need to change this to reflect your names

Two rooms:
room0;
room1;

Two paths:
path0;
path1;

create event of object 'soldier'
Code:
switch (room)
{case room0: is_path = path0; break;
case room1: is_path = path1; break;}
An instance of 'Soldier' was placed in each room.

Global mouse button right released event in 'Soldier'
Code:
if room == room0
{room_goto_next();}
else
{room_goto(room_first);}
Global mouse button left released event in 'Soldier'
Code:
path_start(is_path, 4, path_action_continue, true) ;
What this does: Every press of the right mouse button switches between the two rooms. Every press of the left mouse button starts 'Soldier' moving down the path. What that path is, is defined in it's create event and taken from what room it is in. You can ignore the mouse button things, as they were only there for the purposes of testing.

I had two different paths, and saw it moving along a different path based on what room it was.

The reason this works is because path start is only being called once - only when the left mouse button is pressed. The same goes for having path start in the create event - it is only called once.

If you have path start in a step event it will be called repeatedly, and so the instance will constantly go back to the beginning of the path. When that happens it will appear to not be moving - because it isn't, as it's being told each step to go to the beginning of the path. It has no understanding of already being on a path, and will take that command very literally.

Hopefully that clears up a few things for you.
Hi!

I appreciate your efforts to show me that sollution. Because of I am a programming greenhorn ;-) I can absolutely use such lessons. You explained it very deeply and clear... I just don't want to memorize codes, I want to understand each part and their functions.

I thank you for your time and help, dude_abides.
I hope, I will reach skills one day, I could maybe help you too. :)

Best wishes!
Archie.
 
You're welcome. People on the community helped me when I first started programming, and I try to do the same. Good luck with your project as you go forward :)
 
Top