Clear Keyboard Buffer
BlitzPlus Forums/BlitzPlus Programming/Clear Keyboard Buffer
| ||
Hello, I am using BlitzBasic to make a prototype game, I am wondering if there is a way to clear the keyboard buffer, so that new keyboard data can be inputted. If KeyHit(D_KEY) And Debug_Mode_On = True Then Debug_Mode_On = False ElseIf KeyHit(D) And Debug_Mode_On = False Then Debug_Mode_On = True EndIf If Debug_Mode_On = True Then Text 1,1,"Debug is on" ElseIf Debug_Mode_On = False Then Text 1,1,"Debug is off" EndIf In my code I want to make it so that when debug_mode is on, it will debug is on, and when it is off, that it will say it is off. I use the D key to do this. However when I press D, it turns debug mode off and then the text just says Debug is off, no matter how many times I press D, I can't get it to make it go back and forth between saying debug is off or on. Any help please? |
| ||
Return key hit result to a variable and use the variable instead. |
| ||
Is it the typographic error in the first ElseIf clause? ElseIf KeyHit(D) -> The value in KeyHit should be "D_KEY," not just "D." In any case, I suggest dropping ElseIf and using just Else. ;Flip the current state of 'debugMode.' If KeyHit( D_KEY ) Then debugMode = Not debugMode ;Print information according to the state of 'debugMode.' If debugMode Then Text 1,1,"Debug is on." Else Text 1,1,"Debug is off." EndIfTo understand how 'debugMode' is toggled on and off: on an assignment (on putting a value in a variable), the expression that you're assigning the variable with is evaluated\resolved\calculated first, and then the result is "stored" in the variable. The "NOT" operator inverts the value of a boolean expression. Therefore, if debugMode is FALSE at the moment: debugMode = Not False (which results in True) If debugMode is TRUE at the moment: debugMode = Not True (which results in False) |
| ||
Thanks Kryzon, it works. |