Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: De-Communizer on Sat 18/04/2009 16:34:45

Title: Holding a button to make a value go up...
Post by: De-Communizer on Sat 18/04/2009 16:34:45
My current crazy plot involves making a value increase as I hold a key on the keyboard, and decrease as I hold a second key. I was considering using "IsKeyPressed", but I only need to it alter the value four times a second. I'm sure it has *something* to do with repeatedly execute, but I can't think quite how I'd do it.

i.e. Trying to make it so that when "A" is held, "value" increases, when "B" is held, value decreases.

Thanks again!
Title: Re: Holding a button to make a value go up...
Post by: RickJ on Sat 18/04/2009 17:56:14
I believe the following code will increment/decrement  the value by 1 when the plus/minus keys are pressed.   The keys need to be released, and pressed to increment/decrement the value again.

*** Global Script ***
int Value=0;

function on_key_press (eKeyCode keycode) {
   // Increase-Decrease value
   if (keycode==eKeyPlus) {
      Value++;
   }
   else if (keycode==eKeyHyphen) {
      Value++;
   }
}


To continously increment/decrement the value then something like the following could be used.

*** Global Script ***
int Value=0;

function repeatedly_execute() {
   // Increase-Decrease value
   if (IsKeyPressed(eKeyPlus)) {
      Value++;
   }
   else if (IsKeyPressed(eKeyHyphen)) {
      Value++;
   }
}