October 17, 2018, 07:27:17 AM

Author Topic: How do I add 1 each time a button is pressed[SOLVED]  (Read 244 times)

Offline Borislav

  • Jr. Member
  • **
  • Posts: 39
How do I add 1 each time a button is pressed[SOLVED]
« 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.

Offline STEVIE G

  • Full Member
  • ***
  • Posts: 236
Re: How do I add 1 each time a button is pressed
« Reply #1 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


Offline Matty

  • Hero Member
  • *****
  • Posts: 518
    • MattiesGames
Re: How do I add 1 each time a button is pressed
« Reply #2 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.

Offline Borislav

  • Jr. Member
  • **
  • Posts: 39
Re: How do I add 1 each time a button is pressed
« Reply #3 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