Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: proximity on Thu 07/07/2005 03:10:45

Title: Character doesn't walk continuously (SOLVED)
Post by: proximity on Thu 07/07/2005 03:10:45
  i've used (iskeypressed) command in room's repeatedly_execute section long time ago and it worked well :

// room's repeatedly execute
if (iskeypressed(377)==1)
MoveCharacter(EGO,character[EGO].x+3,character[EGO].y);

My probem is; i wanted to try this command  in room's repeatedly execute again.However, this time, my character didn't walk continuously when i press right arrow key. When i pressed right arrow key, he just kept playing walking animation but didn't move. When i stopped pressing the key, he moved 3 pixels to the right and stopped.

   Why did it not work this time? i used empty game template and version 2.62. Please help! i couldn't find the reason why?
Title: Re: My character doesn't walk continuously
Post by: Kweepa on Thu 07/07/2005 03:36:30
That might depend on the speed of the player character. Too slow and he won't move a pixel in the frame before you tell him to start moving again.
You could try increasing the player character speed (I think that means reducing the "Speed" number in the character "tab").
Title: Re: My character doesn't walk continuously
Post by: strazer on Thu 07/07/2005 03:43:47
Are you sure you hadn't used the MoveCharacter command in the room's on_key_press function? The on_key_press function is only called once, when the key is pressed down.

The way your above code in rep_ex works now is that 40 times per second it's checked if the right arrow key is held down and then, the 3-pixel character move is started, !40 times a second!, so it has no chance to actually be executed until the key is released.

You have to check if the movement has already been started before trying to move the character again. Try something like this:


// room script

bool IsMovingRight;

function room_a() {
  // room's repeatedly execute
  //...

  if (IsKeyPressed(377) == true) { // if right arrow key is held down

    if (IsMovingRight != true) { // if NOT moving right already
      cEgo.Walk(cEgo.x + 3, cEgo.y); // start moving EGO 3 pixels to the right
      IsMovingRight = true; // set movement started
    }

  }
  else IsMovingRight = false; // if right arrow key is NOT held down, set movement NOT started

  //...
}


Check out this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=8303.0) in the Technical Archive on how to do proper multi-directional keyboard control.
Title: Re: My character doesn't walk continuously
Post by: proximity on Thu 07/07/2005 13:05:39
Yes, i am sure i didn't use on_key_press command. When i got wrong result with repeatedly_execute function, i tried also on_key_press function. This time, character didn't move again and also didn't play walking animation.

  This is too weird. i tried this before and it worked. Why is it not working now?

  Wait pls, i will try the script you mentioned and tell you result...

Title: Re: My character doesn't walk continuously
Post by: proximity on Thu 07/07/2005 13:21:55
strazer, the script you gave me didn't work in verison 2.62.  Do you have any other solutions?
Title: Re: My character doesn't walk continuously
Post by: strazer on Thu 07/07/2005 14:01:44
Yes, the code is for version 2.7. This is for v2.62:


// room script

int IsMovingRight;

function room_a() {
  // room's repeatedly execute
  //...

  if (IsKeyPressed(377) == 1) { // if right arrow key is held down

    if (IsMovingRight != 1) { // if NOT moving right already
      MoveCharacter(EGO, character[EGO].x + 3, character[EGO].y); // start moving EGO 3 pixels to the right
      IsMovingRight = 1; // set movement started
    }

  }
  else IsMovingRight = 0; // if right arrow key is NOT held down, set movement NOT started

  //...
}
Title: Re: My character doesn't walk continuously
Post by: proximity on Thu 14/07/2005 03:04:00
Thanks strazer, that worked.