[Tutorial] Keypad Code
Feb 28, 2010 12:03:07 GMT
Post by Zeph on Feb 28, 2010 12:03:07 GMT
Often people want a code to be entered on a keypad to open a door.
Most keypad 'logic' out there isn't quite that good.
I've worked out a decent way to create the keypad, and will share it with you.
This example will use the 4-digit code "5623".
Please note the attached example map does not use this code, it has it's own. See if you can work it out
Tip:
Func_Button (9 or 10 of these)
KeyValues:
Move Direction: (Into the keypad, angle set by top-down view)
Speed: "20"
Lip: "1"
Delay Before Reset: "0.25"
Outputs:
OnPressed -> "Keypad_Input" -> InValue -> "(Button Number)"
Logic_Case "Keypad_Input"
KeyValues:
Case01: "1"
Case02: "2" (Etc, one for each button)
Outputs:
OnCase01 -> "Keypad_Compare" -> SetValueCompare -> "1" (Automatically compares after setting 'Value')
OnCase02 -> "Keypad_Compare" -> SetValueCompare -> "2" (Etc, one for each button)
Logic_Compare "Keypad_Compare"
KeyValues:
CompareValue: "5" (The first digit of your code)
Outputs:
OnEqualTo -> "Keypad_Correct" -> Trigger
OnNotEqualTo -> "Keypad_Wrong" -> Trigger
Logic_Relay "Keypad_Correct"
Outputs:
OnTrigger -> "Keypad_CurrentDidgit" -> Add -> "1" (Loads next code digit)
(Plus any additional outputs to perform when a correct number is entered)
Logic_Relay "Keypad_Wrong"
Outputs:
OnTrigger -> "Keypad_CurrentDigit" -> Set -> "1" (Resets to first code digit)
(Plus any additional outputs to perform when a wrong number is entered, EG: flash red light)
Math_Counter "Keypad_CurrentDigit"
KeyValues:
StartValue: "1"
Outputs:
OutValue -> "Keypad_Code" -> InValue (Automatically fired every time the 'Value' changes)
Logic_Case "Keypad_Code"
KeyValues:
Case01: "1"
Case02: "2"
Case03: "3"
Case04: "4"
Case05: "5" (Number of digits in code + 1)
Outputs:
OnCase01 -> "Keypad_Compare" -> SetCompareValue -> "5"
OnCase02 -> "Keypad_Compare" -> SetCompareValue -> "6"
OnCase03 -> "Keypad_Compare" -> SetCompareValue -> "2"
OnCase04 -> "Keypad_Compare" -> SetCompareValue -> "3"
OnCase05 -> "Keypad_CodeEntered" -> Trigger (End clause)
Logic_Relay "Keypad_CodeEntered"
Outputs:
OnTrigger -> "Keypad_Correct" -> Disable
OnTrigger -> "Keypad_Wrong" -> Disable (These stop the keypad from working further)
(Plus any additional outputs to perform when the full code has been entered,
EG: open a door, start an elevator, play a sound, turn on a green light, etc)
VVV Attachment Below VVV
Most keypad 'logic' out there isn't quite that good.
I've worked out a decent way to create the keypad, and will share it with you.
This example will use the 4-digit code "5623".
Please note the attached example map does not use this code, it has it's own. See if you can work it out
Tip:
[1] [2] [3]
[4] [5] [6]
[7] [8] [9]
Func_Button (9 or 10 of these)
KeyValues:
Move Direction: (Into the keypad, angle set by top-down view)
Speed: "20"
Lip: "1"
Delay Before Reset: "0.25"
Outputs:
OnPressed -> "Keypad_Input" -> InValue -> "(Button Number)"
Logic_Case "Keypad_Input"
KeyValues:
Case01: "1"
Case02: "2" (Etc, one for each button)
Outputs:
OnCase01 -> "Keypad_Compare" -> SetValueCompare -> "1" (Automatically compares after setting 'Value')
OnCase02 -> "Keypad_Compare" -> SetValueCompare -> "2" (Etc, one for each button)
Logic_Compare "Keypad_Compare"
KeyValues:
CompareValue: "5" (The first digit of your code)
Outputs:
OnEqualTo -> "Keypad_Correct" -> Trigger
OnNotEqualTo -> "Keypad_Wrong" -> Trigger
Logic_Relay "Keypad_Correct"
Outputs:
OnTrigger -> "Keypad_CurrentDidgit" -> Add -> "1" (Loads next code digit)
(Plus any additional outputs to perform when a correct number is entered)
Logic_Relay "Keypad_Wrong"
Outputs:
OnTrigger -> "Keypad_CurrentDigit" -> Set -> "1" (Resets to first code digit)
(Plus any additional outputs to perform when a wrong number is entered, EG: flash red light)
Math_Counter "Keypad_CurrentDigit"
KeyValues:
StartValue: "1"
Outputs:
OutValue -> "Keypad_Code" -> InValue (Automatically fired every time the 'Value' changes)
Logic_Case "Keypad_Code"
KeyValues:
Case01: "1"
Case02: "2"
Case03: "3"
Case04: "4"
Case05: "5" (Number of digits in code + 1)
Outputs:
OnCase01 -> "Keypad_Compare" -> SetCompareValue -> "5"
OnCase02 -> "Keypad_Compare" -> SetCompareValue -> "6"
OnCase03 -> "Keypad_Compare" -> SetCompareValue -> "2"
OnCase04 -> "Keypad_Compare" -> SetCompareValue -> "3"
OnCase05 -> "Keypad_CodeEntered" -> Trigger (End clause)
Logic_Relay "Keypad_CodeEntered"
Outputs:
OnTrigger -> "Keypad_Correct" -> Disable
OnTrigger -> "Keypad_Wrong" -> Disable (These stop the keypad from working further)
(Plus any additional outputs to perform when the full code has been entered,
EG: open a door, start an elevator, play a sound, turn on a green light, etc)
VVV Attachment Below VVV