Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Melissa on Mon 01/04/2013 19:18:52

Title: How do I prevent button presses from repeating? [SOLVED]
Post by: Melissa on Mon 01/04/2013 19:18:52
I know that someone has already posted this question:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=32121.msg414514 (http://www.adventuregamestudio.co.uk/forums/index.php?topic=32121.msg414514)

But I couldn't implement khris' code, the process keeps repeating itself when I keep the key pressed

bool down;

//rep_ex

  if (IsKeyPressed(32)) {
    if (!down) {
      down=true;
      // do stuff
    }
  }
  else down=false;


Thank you for helping me :wink:
Title: Re: How do I prevent button presses from repeating?
Post by: Khris on Mon 01/04/2013 19:30:03
Did you put the line "bool down;" above the repeatedly_execute function?

Code (ags) Select
bool down;

function repeatedly_execute() {

  if (IsKeyPressed(32)) {
    if (!down) {
      down=true;
      // do stuff
    }
  }
  else down=false;
}
Title: Re: How do I prevent button presses from repeating?
Post by: Melissa on Mon 01/04/2013 19:34:13
Quote from: Khris on Mon 01/04/2013 19:30:03
Did you put the line "bool down;" above the repeatedly_execute function?

Code (ags) Select
bool down;

function repeatedly_execute() {

  if (IsKeyPressed(32)) {
    if (!down) {
      down=true;
      // do stuff
    }
  }
  else down=false;
}

Ups! :shocked:

Thank you again Khris!