Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: .M.M. on Thu 17/01/2008 17:40:19

Title: problems with long parts of script
Post by: .M.M. on Thu 17/01/2008 17:40:19
Hi, first what I tell is what I need.
Player will set direction and power of shot and then, he will press spacebar and ball will start moving. I have problem with code for keeper. If he will touch ball,  reaction of the ball depends on its height and height of keepers jump (jump is random). This is code (in  repeatedly_execute).
GlobalInt 1 is height of the ball and GlobalInt 3 is height of keepers jump.

if (cKeeper.IsCollidingWithChar (cBall)) {
if (GetGlobalInt (3) ==0)  {
   if (GetGlobalInt (1) >4){
   cBall.StopMoving ();

   cKeeper.StopMoving ();
   Wait (70);
   player.ChangeRoom (1,162,158);
   }
   else if ((GetGlobalInt (1) <3 ) && (GetGlobalInt (1) > 7)) {
   }
   else if ((GetGlobalInt (1) <6 ) && (GetGlobalInt (1) > 10)) {
   }
    else if (GetGlobalInt (1) <9 ){
   } 
  }
// only top part of script works well
else if (GetGlobalInt (3) ==1)  {
   if (GetGlobalInt (1) <4){
   }
   else if ((GetGlobalInt (1) <3 ) && (GetGlobalInt (1) > 7)) {
   cBall.StopMoving ();
   cKeeper.StopMoving ();
   Wait (70);
   player.ChangeRoom (1,162,158);

   }
   else if ((GetGlobalInt (1) <6 ) && (GetGlobalInt (1) > 10)) {
   }
    else if (GetGlobalInt (1) <9 ){
   } 
  }
  else if (GetGlobalInt (3) ==3)  {
   if (GetGlobalInt (1) <4){
   }
   else if ((GetGlobalInt (1) <3 ) && (GetGlobalInt (1) > 7)) {
   }
   else if ((GetGlobalInt (1) <6 ) && (GetGlobalInt (1) > 10)) {
   cBall.StopMoving ();
   cKeeper.StopMoving ();
   Wait (70);
   player.ChangeRoom (1,162,158);
   }
    else if (GetGlobalInt (1) <9 ){
   } 
  }
}

Please, help me, I really can't find where the problem is.
Title: Re: problems with long parts of script
Post by: Khris on Fri 18/01/2008 00:01:56
Alright, it looks like you've mixed up > and <. Plus the script doesn't consider a keeper's height of 2 (it checks for 0, 1 or 3). That might be intentional, but I've assumed otherwise.

  int bh = GetGlobalInt(1);
  int kh = GetGlobalInt(3);

  if (cKeeper.IsCollidingWithChar (cBall)) {

  // keeper  ball
  // ------------
  //   0     0-3
  //   1     4-6
  //   2     7-9

    if (kh==(bh-1)/3) {
      cBall.StopMoving ();
      cKeeper.StopMoving ();
      Wait (70);
      player.ChangeRoom (1,162,158);
    }
  }