Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: YotamElal on Mon 28/02/2005 14:22:59

Title: if character is on x, y ?
Post by: YotamElal on Mon 28/02/2005 14:22:59
is there a script

if (character is on screen co-ordinates x,y){
Title: Re: if character is on x, y ?
Post by: Rui 'Trovatore' Pires on Mon 28/02/2005 15:18:53
You mean like "character[EGO].x"? (rt[f]m)
Title: Re: if character is on x, y ?
Post by: strazer on Mon 28/02/2005 17:42:13
Character.x and .y are room coordinates, not screen coordinates.
To check if a character is at a certain position on the screen, do:


  if ((character[CHARID].x - GetViewportX() == THEXCOORD) && (character[CHARID].x - GetViewportY() == THEYCOORD) {
    // do stuff
  }


If you're referring to his position in the room, remove GetViewportX/Y.
Title: Re: if character is on x, y ?
Post by: YotamElal on Mon 28/02/2005 18:32:17
I tried to use character[EGO].x 
& character[EGO].y
but it didn't work.

I have a character walking around from spot to spot in the repeated actions of the room.
I want the character to say a word each time a path is finished.
Here is my code:
PlZHlP

  if (character[FRA].walking == 0) {
   MoveCharacter (FRA, 163, 210);
   MoveCharacterPath (FRA, 229, 219);
   MoveCharacterPath (FRA, 167, 234);
   MoveCharacterPath (FRA, 167, 216);
   MoveCharacterPath (FRA, 121, 207);
   MoveCharacterPath (FRA, 121, 236);
  }

I tried to add....

if (character[FRA].x==229){
if (character[FRA].y==219){
DisplaySpeech(...)}
}
if (character[FRA].x==167){
if (character[FRA].y==234){
DisplaySpeech(...)}
}

but it didn't work.. :o(
Title: Re: if character is on x, y ?
Post by: DoorKnobHandle on Mon 28/02/2005 18:36:49
It would be alot easier to use this then:


if (character[FRA].walking == 0)
{
   MoveCharacter (FRA, 163, 210);
   DisplaySpeech (...);
   MoveCharacterPath (FRA, 229, 219);
   DisplaySpeech (...);
   MoveCharacterPath (FRA, 167, 234);
   DisplaySpeech (...);
   MoveCharacterPath (FRA, 167, 216);
   DisplaySpeech (...);
   MoveCharacterPath (FRA, 121, 207);
   DisplaySpeech (...);
   MoveCharacterPath (FRA, 121, 236);
   DisplaySpeech (...);
}
Title: Re: if character is on x, y ?
Post by: YotamElal on Mon 28/02/2005 18:47:04
i tried that before...

all the speehes are displayed before the first path and then they arn't displayed at all!!!???!?
Title: Re: if character is on x, y ?
Post by: strazer on Mon 28/02/2005 18:49:26
mamarulez:
The MoveCharacterPath commands buffer the walking commands, they are not blocking, therefore your suggestion won't work.

YotamElal:
Each time the character finishes a path, he is still considered moving.
When a character is moving, for performance reasons the pathfinder can give slightly inaccurate results for the character's coordinates, so it may not be possible to do it your way.

Try this:


function room_a() {
  // script for room: Repeatedly execute

  if (character[FRA].walking == 0) {

    if (character[FRA].x == 163 && character[FRA].y == 210) {
      DisplaySpeech(FRA, "Finished 1st path.");
      MoveCharacter(FRA, 229, 219);
    }
    else if (character[FRA].x == 229 && character[FRA].y == 219) {
      DisplaySpeech(FRA, "Finished 2nd path.");
      MoveCharacter(FRA, 167, 234);
    }
    else if (character[FRA].x == 167 && character[FRA].y == 234) {
      DisplaySpeech(FRA, "Finished 3rd path.");
      MoveCharacter(FRA, 167, 216);
    }
    else if (character[FRA].x == 167 && character[FRA].y == 216) {
      DisplaySpeech(FRA, "Finished 4th path.");
      MoveCharacter(FRA, 121, 207);
    }
    else if (character[FRA].x == 121 && character[FRA].y == 207) {
      DisplaySpeech(FRA, "Finished 5th path.");
      MoveCharacter(FRA, 121, 236);
    }
    else {
      DisplaySpeech(FRA, "Finished last path / Starting.");
      MoveCharacter(FRA, 163, 210);
    }

  }

}


Edit: Fixed DisplaySpeech command.
Title: Perfect!
Post by: YotamElal on Tue 01/03/2005 09:35:47
Perfect!