Sometimes a user input is necessary. G1ANT.Robot allows to ask a user for some input with the dialog.ask
command. And the if
command is a perfect tool to check what was entered.
Run this script:
dialog.ask ‴Enter a digit (0-9):‴ result ♥input
if ♥input=="1"
dialog ‴You entered 1‴
else if ♥input=="2"
dialog ‴You entered 2‴
else if ♥input=="3"
dialog ‴You entered 3‴
else
dialog ‴Your digit is greater than 3 or less than 1‴
end
The dialog.ask
command displays a dialog box with a message of your choice — “Enter a digit (0-9):” in this case — and provides an input box to enter data, which is stored in the ♥input
variable. The if
/else if
/else
block checks what was entered and displays individual dialog boxes for three values (1, 2 and 3) and a common message for any other value.
Note that this time the values in conditions are embraced with quotes (if ♥input=="1"
), because they are text, not numbers (more on this in the next lesson).
But what about an input that is not a digit? In the next lesson you will learn how to handle a wrong user input.