Fuzzzy Piggy,
Okay, the focus is to allow execution of the bomb dropping command, only
once when the trigger button is pressed. Therefore, before executing the command we must check to see what if trigger was pressed on the last program loop.
If the trigger was not pressed on the last loop, but is now pressed on the current loop, we come to an initial press. Then, the command is executed. But, on the next loop(knowing that several program loops can pass during the duration of the physical press of a button ), though the trigger might be currently pressed, it was also pressed on the last loop. So, the command will not execute.
In code, we store a variable,
oldfirebuttonstate, with the value of the joystick fire button state, for the current loop. On the next loop, the code will swing around to the section containing the detection of the keypress. At this point, you not only check for the a current keypress, but you also check the value that is inside of
oldfirebuttonstate. If it contains a 1, then the command is not executed. Else, it is.
Below is a code example(though code is for DarkBasic Classic, I am sure it should be easily convertible to DB Professional).
sync on : sync rate 60
cls
true = 1 : false = 0
repeat
if joystick fire a() = true and oldfirebuttonstate = false
` paste a circle randomly positioned onto the screen
cls
xpos = rnd(screen width()) : ypos = rnd(screen height())
circle xpos,ypos,20
endif
` always update this variable after the section of code that checks its state
oldfirebuttonstate = joystick fire a()
sync
until something = 1
end