Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mouth for war on Wed 07/04/2010 17:44:59

Title: problems with if the character walks or stands still[SOLVED]
Post by: Mouth for war on Wed 07/04/2010 17:44:59
Ok I have a small problem with my game. At one point you have to get past a ghost by playing a little game with him. He turns away from you and only then you may walk...if you walk when he faces you he will notice that you're moving and you have to restart. That thing works but i can't figure out how to solve it when the character isn't moving. here's the code i've got so far

(The timer starts from the global script after a dialog has ended where you choose if you want to play the game with him or not)

function room_RepExec()
{
if (IsTimerExpired(1))
while (cEgo.Moving) {
cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
 cEgo.StopMoving();
cChar27.Say ("Hah you're moving");
cChar27.Say ("You have to start over");
dGhost2.Start();
}
The part below doesn't work at all and I've probably just overlooked something

else if (IsTimerExpired(1)) {
                                             // on this line I guess i want a code  like "If character is not moving" kind of thing
cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
 cChar27.Say ("You're good. Let's continue");
(here i'd like to set a different timer so the intervals between the ghost won't be exactly the same. the first timer from the global script is 400 so the second could be 300 then 100 and maybe a last one at 200)
}
 }
 
Hope anyone can help :D
Title: Re: problems with if the character walks or stands still
Post by: Khris on Wed 07/04/2010 18:31:57
You have to rearrange that:

function room_RepExec()
{
  if (IsTimerExpired(1)) {
    if (cEgo.Moving) {
      cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
      cEgo.StopMoving();
      cChar27.Say ("Hah you're moving");
      cChar27.Say ("You have to start over");
      dGhost2.Start();
    }
    else {  // player isn't moving
      cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
      cChar27.Say ("You're good. Let's continue");
    }
  }
}


IsTimerExpired() will only return true once, and false afterwards.
Title: Re: problems with if the character walks or stands still
Post by: Mouth for war on Wed 07/04/2010 18:38:51
That worked almost but the thing is that as soon as I enter the room the ghost says "You're good. Let's continue" He shouldn't say that until the game begins. Here's what's supposed to happen. You enter the room from the right and if you try to exit to the left the ghost appears and he speaks with you and after you have spoken you can accept his challenge or choose not to do it and then i have a run-script from the dialog and this is what happens in the globalscript after you choose to accept

FadeOut(30);
cChar27.FaceLocation(cChar27.x - 50, cChar27.y);
cEgo.x = (790);
cEgo.y = (504);
cEgo.PlaceOnWalkableArea();
cEgo.FaceLocation(cEgo.x - 50, cEgo.y);
Wait(100);
FadeIn(10);
//Game begins
SetTimer(1, 400);
Title: Re: problems with if the character walks or stands still
Post by: Mouth for war on Wed 07/04/2010 19:17:08
Ok I solved it by adding a variable into it. But thanks Khris you helped me :D

function room_RepExec()
{
  if (IsTimerExpired(1)) {
    if (cEgo.Moving) {
      cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
      cEgo.StopMoving();
      cChar27.Say ("Hah you're moving");
      cChar27.Say ("You have to start over");
      dGhost2.Start();
    }
    else if (Ghostgame ==2){  // player isn't moving
      cChar27.FaceLocation(cChar27.x + 10, cChar27.y);
      cChar27.Say ("You're good. Let's continue");
    }
  }