Console input
Ask the person a question, hide a password while they type it, or let them pick from a menu.
ask
Otter
ask "What is your name? " and call it userName
say "Hello" userName
ask prints the prompt, waits for a line, and stores it under the name you gave. What was typed is converted when it looks like something else: 42 becomes the number 42, and true or false becomes a boolean. Everything else stays text.
Otter
ask "Enter your age: " and call it age
age and 5 make futureAge
say "In 5 years you will be:" futureAge
Secret input
Otter
ask secretly "Password:" and call it pw
While the person types, the screen shows * for each character instead of the characters themselves. The variable holds what they really typed, so treat it carefully: compare it, hash it, and never say it.
Storing a secret for later? Use the credential vault instead of a variable or a file.
Menus
Otter
options are
"Small"
"Medium"
"Large"
.
choose from options into choice
say "You chose" choice
Output
1. Small
2. Medium
3. Large
Choose a number: 2
You chose Medium
choose from lists the items with numbers and asks for one. It asks again if the answer is not a number in range, and it stores the chosen item itself, not its position. Choosing from an empty list is an error.
Input the program was started with
Values typed after the program name arrive in the built-in arguments list - see The otter command.
Console programming
Cryptography and secrets
The otter command