This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jtdavis99's profile picture

Choices?

Started by jtdavis99, 03 March 2012 - 03:40 AM
jtdavis99 #1
Posted 03 March 2012 - 04:40 AM
How would I go about making multiple choices? (As in, press 1 for ___ and 2 for ___)
Advert #2
Posted 03 March 2012 - 05:00 AM
You can use read(), and check what it returned:


print("Press 1 for pie, and 2 for cake.")
local input = read()
if input == "" then -- The user just pressed enter
 print("How about some errors instead?")
 error("User refuses pie and/or cake.")
elseif input == "1" then
 print("Here's your pie.")
elseif input == "2" then
 print("Here's your cake.")
else
 print("There is no option 3.")
end