Holding a button to make a value go up...

Started by De-Communizer, Sat 18/04/2009 16:34:45

Previous topic - Next topic

De-Communizer

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!

RickJ

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.
Code: ags

*** 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.
Code: ags

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

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

SMF spam blocked by CleanTalk