Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Thu 08/12/2011 13:28:37

Title: if player is in particular rooms - batched condition in one line
Post by: steptoe on Thu 08/12/2011 13:28:37
Hi

rather than making separate cspit move distance for every room I'm trying to bunch together for various rooms except a few where the cspit move is higher up the screen.

Like if player is in 1,2,3,4,5 this distance but if player is in 6 this distance.

When I go with below code it does not seem to make any difference in Room 6.

Example:

{  // SHOOT cspit distance in these rooms = 140
 
 if ((keycode == eKeySpace)&& player.Room==1  || player.Room==2 || player.Room==3 || player.Room==4)
{
   ginfo.Visible=false;
   cEgo.LockView(5);
   cEgo.Animate(0, 3, eOnce, eBlock);
   cEgo.UnlockView();
   Wait(60);
   Spit=(Spit -1);
   cspit.FollowCharacter(null);
   cspit.Transparency=0;
   cspit.Move(cspit.x + 0, cspit.y - 140, eBlock, eAnywhere);
   cspit.Transparency=100;
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   cspit.Move(cspit.x + 0, cspit.y + 140, eNoBlock, eAnywhere);
}
  // SHOOT cspit distance in these rooms = 190

 else if ((keycode == eKeySpace)&& player.Room==6)
{
   ginfo.Visible=false;
   cEgo.LockView(5);
   cEgo.Animate(0, 3, eOnce, eBlock);
   cEgo.UnlockView();
   Wait(60);
   Spit=(Spit -1);
   cspit.FollowCharacter(null);
   cspit.Transparency=0;
   cspit.Move(cspit.x + 0, cspit.y - 190, eBlock, eAnywhere);
   cspit.Transparency=100;
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
  cspit.Move(cspit.x + 0, cspit.y + 190, eNoBlock, eAnywhere);
}


Double thanks for any help

cheers




Title: Re: if player is in particular rooms - batched condition in one line
Post by: Joe on Thu 08/12/2011 13:37:36
Since the OR operator has lower priority than the AND one you may solve this like the followoing:


{  // SHOOT cspit distance in these rooms = 140

if(keycode == eKeySpace){

 if ( player.Room==1  || player.Room==2 || player.Room==3 || player.Room==4)
 {
   ginfo.Visible=false;
   cEgo.LockView(5);
   cEgo.Animate(0, 3, eOnce, eBlock);
   cEgo.UnlockView();
   Wait(60);
   Spit=(Spit -1);
   cspit.FollowCharacter(null);
   cspit.Transparency=0;
   cspit.Move(cspit.x + 0, cspit.y - 140, eBlock, eAnywhere);
   cspit.Transparency=100;
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   cspit.Move(cspit.x + 0, cspit.y + 140, eNoBlock, eAnywhere);
 }
  // SHOOT cspit distance in these rooms = 190

 else if ( player.Room==6)
 {
   ginfo.Visible=false;
   cEgo.LockView(5);
   cEgo.Animate(0, 3, eOnce, eBlock);
   cEgo.UnlockView();
   Wait(60);
   Spit=(Spit -1);
   cspit.FollowCharacter(null);
   cspit.Transparency=0;
   cspit.Move(cspit.x + 0, cspit.y - 190, eBlock, eAnywhere);
   cspit.Transparency=100;
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
  cspit.Move(cspit.x + 0, cspit.y + 190, eNoBlock, eAnywhere);
 }
}


You could also use parentesis but I think this is better.
Title: Re: if player is in particular rooms - batched condition in one line
Post by: Wyz on Thu 08/12/2011 13:38:03
It might be better for efficiency and readebility to split the selection and execution of the distance in two parts like this:

Quote
int SpitDistance()
{
  if (cEgo.Room < 5)
    return 140;
  else
    return 190;
}

if (keycode == eKeySpace)
{
    ginfo.Visible=false;
    cEgo.LockView(5);
    cEgo.Animate(0, 3, eOnce, eBlock);
    cEgo.UnlockView();
    Wait(60);
    Spit=(Spit -1);
    cspit.FollowCharacter(null);
    cspit.Transparency=0;
    cspit.Move(cspit.x + 0, cspit.y - SpitDistance(), eBlock, eAnywhere);
    cspit.Transparency=100;
    cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   cspit.Move(cspit.x + 0, cspit.y + SpitDistance(), eNoBlock, eAnywhere);
}

Title: Re: if player is in particular rooms - batched condition in one line
Post by: Khris on Thu 08/12/2011 13:38:36
Again, you have lots of unnecessary duplicate code. The operator for OR is ||, not |. You don't need to go through all numbers one by one though.

{  // SHOOT cspit distance in these rooms = 140
 
  int dist = 140;
  if (player.Room == 6) dist = 190;

  if (keycode == eKeySpace) {
    ginfo.Visible=false;
    cEgo.LockView(5);
    cEgo.Animate(0, 3, eOnce, eBlock);
    cEgo.UnlockView();
    Wait(60);
    Spit--;
    cspit.FollowCharacter(null);
    cspit.Transparency=0;

    cspit.Move(cspit.x + 0, cspit.y - dist, eBlock, eAnywhere);

    cspit.Transparency=100;
    cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);

    cspit.Move(cspit.x + 0, cspit.y + dist, eNoBlock, eAnywhere);
  }
}


And again, you're calling FollowCharacter and Move commands in rapid succession. Did anything I said in the last thread register at all?
Title: Re: if player is in particular rooms - batched condition in one line
Post by: steptoe on Thu 08/12/2011 14:00:54
Hi

Khris: I implemented what you mentioned and it seems to stop collision detection on objects (PPCollision).

AFAIK
If you have a npc follow player exactly then you shoot it (like bullet from a gun) it won't shoot because of the follow command. That is why I called it follow null to shoot then have it transparent and then follow (move) back to return to player. If this makes any sense?

Was not sure how else to do it.

cheers






Title: Re: if player is in particular rooms - batched condition in one line
Post by: Khris on Thu 08/12/2011 14:05:40
Right, but the Move after the FollowCharacter, does it do anything?

And all that aside, I don't think you need the FollowCharacter at all; if this is just to make sure that the spit originates from the character's position, all you have to do is put it there before calling the move command:

  cspit.x = player.x;
  cspit.y = player.y;
  cspit.Move(player.x, player.y + distance, ...);
Title: Re: if player is in particular rooms - batched condition in one line
Post by: steptoe on Thu 08/12/2011 14:19:45
Thanks Khris

Yeah, maybe you are right. Simply 'follow' player will move npc back to player anyway. Cheers, I'll look into doing that.

I like the script about moving npc in relation to player.

cheers again

I need to sort out the collision part.

:=