Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rocko775 on Thu 11/02/2010 17:32:56

Title: Guard Patrol
Post by: rocko775 on Thu 11/02/2010 17:32:56
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);

}

Title: Re: Guard Patrol
Post by: NsMn on Thu 11/02/2010 17:41:19
This is good so far. You should add something like this in the room's repeatedly execute:


if(cguard.x==25)cguard.AddWalkToPoint(100, 185);
else if(cguard.x==99)cguard.AddWalkToPoint(26,185);
Title: Re: Guard Patrol
Post by: rocko775 on Thu 11/02/2010 18:45:51
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)?

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
Title: Re: Guard Patrol
Post by: NsMn on Thu 11/02/2010 19:03:41
Ohright, uhm, yeah, that's pretty ridiculous, sorry  :-[
You already did it right, it has to be AddWaypoint().
Title: Re: Guard Patrol
Post by: rocko775 on Thu 11/02/2010 19:32:52
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,

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


I have version AGS 3.1.2 SP1 would this cause any trouble?
Title: Re: Guard Patrol
Post by: GarageGothic on Thu 11/02/2010 20:39:42
It's because you're calling Character.Walk from RepExec() without any conditionals (so he restarts walking every frame).

Try this:

function room_RepExec() {
  if (cGuard.Moving == false) {
    if (cGuard.x > 200) cGuard.Walk(26, 185);
    else cGuard.Walk(220, 140);
    }
}
Title: Re: Guard Patrol
Post by: rocko775 on Thu 11/02/2010 21:16:38
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.
Title: Re: Guard Patrol
Post by: tzachs on Thu 11/02/2010 21:50:12
Yes, you can do it with the help of the wonderful Character Control Module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=28821.0) which makes these kind of tasks simpler.
Title: Re: Guard Patrol
Post by: suicidal pencil on Thu 11/02/2010 21:56:26
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


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
Title: Re: Guard Patrol
Post by: Khris on Fri 12/02/2010 00:10:28
Btw, you don't need the inner brackets.

    if(cGuard.x == 100 && cGuard.y == 100) cGuard.Walk(100, 400);
Title: Re: Guard Patrol
Post by: suicidal pencil on Sat 13/02/2010 03:56:16
I find it a bit easier to deal with when things are (encompassed) in [brackets] I guess it's programmer's choice :P