char event

From ComputerCraft
Jump to: navigation, search
char
Event
Returns
  • character : string The character the user typed

Source CC:Tweaked

Occurs every time the user typed a letter.

ExampleExampleUsing char event
Ask a question that can be answered based on typing a character.
Code
while true do
  print("Do you like pancakes? Press Y/N for yes or no.")

  local event, character = os.pullEvent("char")

  if character == "y" or character == "Y" then
    print("Great! I like pancakes aswell!")
    break
  elseif character == "n" or character == "N" then
    print("Ahw. Perhaps some soup then?")
    break
  else
    print("Sorry, but", character, "is not a valid answer!")
  end
end