Mr909, your timer problem is because you're using strange methods for timing(eg: dividing integers is never a good idea for reliability). Here's more what I meant (It's a little longer but it'll give you more stable results and you can use it for UP, UP, LEFT, RIGHT, RIGHT, KICK, PUNCH -style cheats too):
remstart
+-------------------------------+---+----+---+
| nonZero Tutorials - Key Combo | = | [] | X |
+-------------------------------+---+----+---+
| Hypothetical scenario: You make a game and |
| Your cheat code is "dark" |
| |
| |
| +--------+ |
| | OK | |
| +--------+ |
+--------------------------------------------+
remend
// Constants - I have a file with proper friendly key names in my Functions Library but this'll do for now.
#CONSTANT qkey KEYSTATE(16)
#CONSTANT dkey KEYSTATE(32)
#CONSTANT akey KEYSTATE(30)
#CONSTANT rkey KEYSTATE(19)
#CONSTANT kkey KEYSTATE(37)
#CONSTANT maxTMR 5000
// Setup
SYNC RATE 60: SET DISPLAY MODE DESKTOP WIDTH(), DESKTOP HEIGHT(), 32
// Variables
cheatFLAG = 0 ` <-- What track's your cheat code inout
cheatTMR = maxTMR ` <-- We'll be using this as our tracker
gameTMR = 0 ` <-- We'll be assigning it later, just introducing it here.
` This would represent your game's internal timer.
// Main
WHILE qkey = 0
CLS
PRINT "Welcome! Press a combo (" + CHR$(34) + "dark" + CHR$(34) + ") to enable or q/esc to quit"
gameTMR = TIMER() ` <-- Tracking the timer
IF pressed = 0 ` <-- Only check if previous key released
pressed = (dkey + akey + rkey + kkey) ` <-- Get TRUE/FALSE on keypress within sequence
IF SCANCODE() > 0 AND pressed = 0 ` <-- Check for non-dark presses
cheatFLAG = 0 ` Since this check only need be performed in this context we place it here
cheatTMR = 0
ENDIF
ENDIF
IF pressed = 1 ` <-- No multi-pressing!
pressed = 2 ` <-- Just set pressed flag to a number outside the condition-checks (namely 1 and 0)
SELECT cheatFLAG ` <-- In DBPro, there's only support for numeric-value cases.
CASE 0
IF dkey = 1: cheatFLAG = 1: cheatTMR = maxTMR: ELSE: cheatTMR = 0: cheatFLAG = 0: ENDIF
ENDCASE
CASE 1
IF akey = 1: cheatFLAG = 2: cheatTMR = maxTMR: ELSE: cheatTMR = 0: cheatFLAG = 0: ENDIF
ENDCASE
CASE 2
IF rkey = 1: cheatFLAG = 3: cheatTMR = maxTMR: ELSE: cheatTMR = 0: cheatFLAG = 0: ENDIF
ENDCASE
CASE 3
IF kkey = 1: cheatFLAG = 4: cheatTMR = maxTMR: ELSE: cheatTMR = 0: cheatFLAG = 0: ENDIF
ENDCASE
ENDSELECT
IF cheatFLAG = 4
CheatConsole()
cheatFLAG = 0
cheatTMR = 0
ENDIF
ENDIF
timelapse = TIMER() - gameTMR ` <-- Get the elapsed time
cheatTMR = cheatTMR - timelapse ` <-- Subtract elapsed time from the cheat-timer
IF cheatTMR <= 0: cheatFLAG = 0: cheatTMR = 0: ENDIF ` <-- If time's up, cancel combo
IF SCANCODE() = 0: pressed = 0: ENDIF ` <-- Do checking for keylift at end here
ENDWHILE
END
` ====================================================================================================================================
Function CheatConsole()
PRINT "": PRINT "":
PRINT "-------- Cheatz Console ---------------"
INPUT "Enter a cheat to activate it >", inp$
PRINT "Sorry, " + CHR$(34) + inp$ + CHR$(34) + " ain't available as there's no game!"
PRINT ""
PRINT "Press any key"
WAIT KEY
EndFunction
Obviously this is a template so I called the cheat console statically. In the game you'd maybe have to call it dynamically to keep the background things animated or whatever - if you wanted to (Personally, I like everything to freeze to I'd have called it statically) in my game.
This method's a little complex. Phaelax's method will be okay if it's just a simple words and you don't mind if other inputs like arrow keys don't cancel the cheat input. If you need to keep it simple, then use his method with the ENTRY BUFFER.