Advertisement
Derek1017

Test

May 3rd, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. -- Computer Light Switch
  2. local side = "left"      -- Set the side for the redstone output
  3. local userinput = ""     -- Initialize user input
  4. local event = ""         -- Initialize event
  5.  
  6. redstone.setOutput(side, false)    -- Clear output, just in case.
  7.  
  8. while true do
  9.  
  10. -- First part of the loop, lamp is off.
  11.   term.clear()                       -- clear the screen
  12.   term.setCursorPos(1,1)             -- Put the cursor at the top left corner.
  13.   print("To turn lamp on, press L.")
  14.   print("To exit, press any other key.")
  15.  
  16. -- Wait for user input (as a character), convert it to uppercase.
  17.   event, userinput = os.pullEvent("char")
  18.   userinput = string.upper(userinput)
  19.  
  20. -- Check to see if the input is an L, otherwise, break the loop.
  21.   if userinput == "L" then
  22.     redstone.setOutput(side, true) -- Turn on the redstone output
  23.   else
  24.     term.clear()
  25.     break
  26.   end
  27.  
  28.   term.clear()                     -- clear the screen
  29.   term.setCursorPos(1,1)           -- Put the cursor at the top left corner
  30.   print("To turn lamp off, press L.")
  31.   print("To exit, press any other key.")
  32.  
  33. -- Wait for user input (as a character), convert it to uppercase.
  34.   event, userinput = os.pullEvent("char")
  35.   userinput = string.upper(userinput)
  36.  
  37. -- Check to see if the input is an L, otherwise, break the loop.
  38.   if userinput == "L" then
  39.     redstone.setOutput(side, false) -- Turn off the redstone output
  40.   else
  41.     term.clear()
  42.     break
  43.   end
  44.  
  45. end -- End of while true loop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement