Guard Patrol

Started by rocko775, Thu 11/02/2010 17:32:56

Previous topic - Next topic

rocko775

I haven't seen anything on the forums or tutorials so I thought I'd ask. If there info is can you link me to it? Is there any way to get a character to "patrol" back and forth from points A and B? I got it so when load the screen the character goes to another spot, but I'm not sure how you get him to go back to the original spot and go on a loop back and forth so he doesn't do it once? Thanks.


function room_AfterFadeIn()
{
cguard.Walk(26, 185);

}


NsMn

This is good so far. You should add something like this in the room's repeatedly execute:

Code: ags

if(cguard.x==25)cguard.AddWalkToPoint(100, 185);
else if(cguard.x==99)cguard.AddWalkToPoint(26,185);

rocko775

Well I can see how that would work but now It gives me this error message. And after I posted that message I figured out that I could use use "Add way point" to get my character to go to another spot.  Would this cause trouble or having my guy walk and do this repeatedly execute function conflict?

Error:
Failed to save room room1.crm; details below
room1.asc(14): Error (line 14): '.AddWalkToPoint' is not a public member of 'Character'. Are you sure you spelt it correctly (remember, capital letters are important)?

Code: ags
function room_AfterFadeIn()
{

cguard.Walk(26, 185);
cguard.AddWaypoint(220, 140);


}
function repeatedly_execute() 
{
if(cguard.x==25)cguard.AddWalkToPoint(100, 185); //line 14
else if(cguard.x==99)cguard.AddWalkToPoint(26,185);
{



Thanks

NsMn

Ohright, uhm, yeah, that's pretty ridiculous, sorry  :-[
You already did it right, it has to be AddWaypoint().

rocko775

Well it should work but now all he does is have a walking movement, but he doesn't go anywhere. It works if I do function room_AfterFadeIn(), but not function room_RepExec(). And if I do afterFadeIn he only does it once,

Code: ags
function room_RepExec()
{
cguard.Walk(26, 185);
cguard.AddWaypoint(220, 140);
}


I have version AGS 3.1.2 SP1 would this cause any trouble?

GarageGothic

It's because you're calling Character.Walk from RepExec() without any conditionals (so he restarts walking every frame).

Try this:

Code: ags
function room_RepExec() {
  if (cGuard.Moving == false) {
    if (cGuard.x > 200) cGuard.Walk(26, 185);
    else cGuard.Walk(220, 140);
    }
 }

rocko775

Sweet! It worked. Thanks.

I'm just wondering can you get him to do more spots than two, like a square or is really complex? I'm not going to do it, I just would like to know if it's possible.

tzachs

Yes, you can do it with the help of the wonderful Character Control Module which makes these kind of tasks simpler.

suicidal pencil

Quote from: rocko775 on Thu 11/02/2010 21:16:38
...can you get him to do more spots than two, like a square...?

Anything is possible :P

Code: ags

function room_RepExec()
{
  if(!cGuard.Moving)
  {
    if((cGuard.x == 100) && (cGuard.y == 100)) cGuard.Walk(100, 400);
    if((cGuard.x == 100) && (cGuard.y == 400)) cGuard.Walk(400, 400);
    if((cGuard.x == 400) && (cGuard.y == 400)) cGuard.Walk(400, 100);
    if((cGuard.x == 400) && (cGuard.y == 100)) cGuard.Walk(100, 100);
  }
}


a brief little code snippet on your guard walking in a counter-clockwise rotation in a square with 300-pixel sides

Khris

Btw, you don't need the inner brackets.

Code: ags
    if(cGuard.x == 100 && cGuard.y == 100) cGuard.Walk(100, 400);

suicidal pencil

I find it a bit easier to deal with when things are (encompassed) in [brackets] I guess it's programmer's choice :P

SMF spam blocked by CleanTalk