Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Valentine on Mon 13/08/2007 23:47:08

Title: Trouble with WalkStraight [Solved]
Post by: Valentine on Mon 13/08/2007 23:47:08
Hi, I'm trying to get a background character to walk in one of my game scenes, but I'm having trouble setting the points he goes through. I want him to walk through four points, then back to the first, but when testing, he just goes straight to the last point.

This is the code I'm using:

cGuard.WalkStraight(200, 200);
cGuard.WalkStraight(300, 200);
cGuard.WalkStraight(300, 300);
cGuard.WalkStraight(200, 300);

Now I'm pretty sure I need to utilise the Moving property to check whether the characters got to each position before going on to the next, but I'm not sure how to put it all together into a working script.

Thanks to anyone who can help me.
Title: Re: Trouble with WalkStraight
Post by: Khris on Tue 14/08/2007 00:05:17
The solution is right here:
http://www.adventuregamestudio.co.uk/manual/Character.AddWaypoint.htm
Title: Re: Trouble with WalkStraight
Post by: Valentine on Tue 14/08/2007 00:31:18
Ahhh.. Thanks for that.

I saw that in some three year old code I looked at trying to figure out my problem, but must have missed it in the manual. I assumed it had been taken out. Silly me!

==EDIT==

ok, i'm having some trouble again now. I want the character to walk about in the background somewhat randomly, but as soon as I move the character into the game, the game freezes up, and I have to Alt-X out. This is the code I'm using:

  // script for Room: Repeatedly execute

int BoxControl = 0;
while (cBox.Room==1) { BoxControl=Random(3);
               if (BoxControl == 0) { cBox.WalkStraight(cBox.x+50, cBox.y+50); }
               if (BoxControl == 1) { cBox.WalkStraight(cBox.x-50, cBox.y+50); }
               if (BoxControl == 2) { cBox.WalkStraight(cBox.x+50, cBox.y-50); }
               if (BoxControl == 3) { cBox.WalkStraight(cBox.x-50, cBox.y-50); }
               }

I'll add some code later to make sure the character doesn't go outside a defined area, but at the moment, I just want to get this bit working.

I've made sure the characters on a walkable area, which it definately is (I've made the entire room walkable to make sure).

Thanks for any help.
Title: Re: Trouble with WalkStraight - New problem, see third post edit
Post by: Khris on Tue 14/08/2007 17:10:13
The game freezes because it gets stuck in the while loop.
The character doesn't leave the room, so cBox.Room will always be 1.
Replace "while (cBox.Room==1)" with "if (!cBox.Moving)" and it should work.
Title: Re: Trouble with WalkStraight [Solved]
Post by: Valentine on Tue 14/08/2007 17:47:23
Thankyou very much for that :)

Just for my understanding (I can't remember reading it in the manual), what does the ! infront of the character name signify?
Title: Re: Trouble with WalkStraight [Solved]
Post by: Khris on Tue 14/08/2007 20:01:50
! is the logical not; I used it here because I want the code to be executed only if the character *isn't* moving.
Title: Re: Trouble with WalkStraight [Solved]
Post by: strazer on Thu 16/08/2007 16:53:18
That means "if (!cBox.Moving)" is the same as "if (cBox.Moving == false)" just as "if (cBox.Moving)" is the same as "if (cBox.Moving == true)".

It's shorter the ! way, but I personally write everything out to make it easier to read.