SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: Borislav on May 16, 2018, 01:41:36 PM

Title: How do I add 1 each time a button is pressed[SOLVED]
Post by: Borislav on May 16, 2018, 01:41:36 PM
I want the script to add 1 once when the button is pressed, but instead, it adds and adds and adds 1 to the value.
I am trying to make a program that will create bricks once when a button is pressed.
Title: Re: How do I add 1 each time a button is pressed
Post by: STEVIE G on May 16, 2018, 04:53:36 PM
I suspect you are using KeyDown rather than Keyhit?  There are various ways of doing this but it might be helpful to see your code first?

Cheers
Stevie

Title: Re: How do I add 1 each time a button is pressed
Post by: Matty on May 16, 2018, 11:13:25 PM
Depending on the language used (blitz3d keyhit) you might want to detect on a 'keyup' state - ie when it changes from keydown to keyup....it is a change in key state you want not the actual state. So store the previous state 'down' and then when the state changes to 'up' record the increment.
Title: Re: How do I add 1 each time a button is pressed
Post by: Borislav on May 17, 2018, 06:47:31 PM
I suspect you are using KeyDown rather than Keyhit?  There are various ways of doing this but it might be helpful to see your code first?

Cheers
Stevie
Oh my god thank you so much! (I used KeyDown because normal buttons glitch with KeyHit)  :D