sting251 wrote:
How would I do the get key if I want it to have to have a series of numbers entered before it resets?
And is there a way to only be able to type in the code after a certain amount of time?
And is there a way to only be able to type in the code after a certain amount of time?
All of this is possible, though a little complicated. The getKey command returns a number corresponding to the latest keypress on the keypad. For instance, if getKey is used while ENTER is pressed, a 105 will be returned, and if 7 is pressed, a 72 will be returned. Here's a handy chart for the getKey codes:
So, while Input cannot run alongside an event loop, a getKey and some ingenuity can. The following code snippet will store input from getKey (provided it was a number) into an accurate numerical value in N. When combined with the previous code, we can produce a multi-digit number inputter alongside a running timer.
Code:
getKey->K
toString(K->Str1
(inString("102 92 93 94 82 83 84 72 73 74",Str1)-1)/4->N
Now that snippet can be integrated into the previous code. The following code will visibly count down a timer (currently set at 500 seconds), while at the same time accepting user input (from the number keys) and displaying that on the screen. Pressing enter or time ending will display win/loss results. The only way to win is to press enter before the time runs out, and have the inputted number be identical to a 10 digit max number stored in L2. Put the number in L2 before the program starts. For instance, if you want the required number to be 276475, store {0,0,0,0,2,7,6,4,7,5} to L2. I have not yet implemented only accepting input after a certain time.
Code:
ClrHome
Output(2,1,"Press ENTER
Output(1,3,":
DelVar A
Delvar B
10->dim(L1
Fill(0,L1
startTmr->T
Repeat not(E) or A or K=105 //checks if enter is pressed or time is up
500-checkTmr(T->E //sets the timer to count down from 500 seconds
Output(1,1,iPart(E/60
Output(1,4,remainder(E,60
getKey->K
toString(K->Str1
(inString("102 92 93 94 82 83 84 72 73 74",Str1)-1)/4->N
If N>-1
N->L1(10-B //stores inputted number to the proper place value in L1
B+1->B //advances place value
Output(5,10-B,N //displays inputted number in correct place value
End
If E and L1=L2 //if time is not up and number is correct
Then
Output(3,1,"You WIN!"
Else
Output(3,1,"You LOSE!"
End
Pause