Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Squinky on Thu 06/10/2005 04:47:42

Title: Why isn't this code working right?
Post by: Squinky on Thu 06/10/2005 04:47:42
I've got a game I'm tidying up still in v.256d. I'm just gonna go with it in that version since the newer version seems so different. My prob is I have a room with a vulture that flys across the top of the screen when you enter. Works okay normally, but if you leave before it crosses the screen it starts up in weird places the next time you enter or just gets stuck in place. I can't wrap my head round it, so heres the little bit of code:

// room script file
int vcount;

// script for room: Player enters screen (after fadein)
//-----Vulture Movement--------------
if (vcount==0){
vcount++;
MoveCharacterDirect (V,46, 9);


}
else if (vcount==1){
Ã,  vcount++;
character [V].x=259;
character [V].y=26;Ã, 
MoveCharacterPath (V,163, 22);
MoveCharacterPath(V,143, 8);
MoveCharacterPath (V,167, 6);
MoveCharacterPath (V,49, 7);Ã, 


}
else if (vcount==2){
Ã,  vcount++;
Ã,  }

else if (vcount==3){
vcount=1;Ã,  Ã, 
character [V].x=86;
character [V].y=6;
MoveCharacterPath (V,219, 34);

MoveCharacterPath (V,167, 6);
MoveCharacterPath (V,281, 12);

}
//------------------------------------------------

Anubody have any ideas?
Title: Re: Why isn't this code working right?
Post by: Gilbert on Thu 06/10/2005 06:19:38
I think there're probably some glitch in the engine, that when you change room, characters in the original room will continue to move, but using walkable area in the new room, worse of all the movement can screw up because of the path finding.

The most offending part is probably the (vcount==2) case, since you don't know where the vulture will last rest on when you enter the room again (but for vcount==1, or 3 case, since you reset the position, it would make less problem.)

My suggestion is:
A) Set also the coordinates of V in case (vcount==2)
B) Before whenever you want to set its coordinates, stop it first, since setting the coordinates of a character while it's still moving can cause strange problems.

So:

// room script file
int vcount;

// script for room: Player enters screen (after fadein)
//-----Vulture Movement--------------
if (vcount==0){
Ã,  vcount++;
Ã,  MoveCharacterDirect (V,46, 9);
} else if (vcount==1){
Ã,  vcount++;
Ã,  StopMoving(V); //B
Ã,  character [V].x=259;
Ã,  character [V].y=26;Ã, 
Ã,  MoveCharacterPath (V,163, 22);
Ã,  MoveCharacterPath(V,143, 8);
Ã,  MoveCharacterPath (V,167, 6);
Ã,  MoveCharacterPath (V,49, 7);Ã, 
} else if (vcount==2){
Ã,  vcount++;
Ã,  StopMoving(V); //B
Ã,  character[V].x=100; //A, substitute desired coordinations here;
Ã,  character[V].y=100; //You can use off-screen ones to make it disappear
} else if (vcount==3){
Ã,  vcount=1;Ã,  Ã, 
Ã,  StopMoving(V); //B
Ã,  character [V].x=86;
Ã,  character [V].y=6;
Ã,  MoveCharacterPath (V,219, 34);
Ã,  MoveCharacterPath (V,167, 6);
Ã,  MoveCharacterPath (V,281, 12);
}
//------------------------------------------------

Title: Re: Why isn't this code working right?
Post by: Squinky on Thu 06/10/2005 06:35:24
That did the trick pretty much. It works much better now, but if I leave the screen while it is still in flight, it will show it for a brief second when I come back, then hop over to its new place. Still much better though, thanks gil.

Now, I'm just wondering what to do to mark this sucker of my list of bugs...
Title: Re: Why isn't this code working right?
Post by: Gilbert on Thu 06/10/2005 07:45:44
Quote from: Squinky on Thu 06/10/2005 06:35:24
it will show it for a brief second when I come back, then hop over to its new place. Still much better though, thanks gil.

Try to move the codes to "(before fade-in)" instead :)
Title: Re: Why isn't this code working right?
Post by: Squinky on Thu 06/10/2005 16:54:33
Heh, simple solution, thanks. All is good now.