plusNick

Nick's Memo Program

Jan 10th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.83 KB | None | 0 0
  1. --[Variables]--
  2. local monside = "right" --side of monitor
  3.  
  4. --[Main Code]--
  5. function test()
  6.   if term.isColor() == false then
  7.     print("An Advanced Computer is required to run this program")
  8.     sleep(3)
  9.     os.shutdown()
  10.   elseif peripheral.getType(monside) ~= "monitor" then
  11.     print("An Advanced Monitor is requred to run this program")
  12.     sleep(3)
  13.     os.shutdown()
  14.   else
  15.     mon = peripheral.wrap(monside)
  16.     width, height = mon.getSize()
  17.     centretxt = (width/2)-2.5
  18.     mon.setBackgroundColor(colors.white)
  19.     mon.clear()
  20.     note1 = 0
  21.     note2 = 0
  22.     note3 = 0
  23.     note4 = 0
  24.     note5 = 0
  25.     if width < 29 then
  26.       print("The monitor on the "..monside.." must be at least 3 wide")
  27.       sleep(3)
  28.       os.shutdown()
  29.     elseif height < 7 or height > 12 then
  30.       print("The monitor on the "..monside.." must be only 2 high")
  31.       sleep(3)
  32.       os.shutdown()
  33.     end
  34.   end
  35. end
  36.  
  37. function drawTerm()
  38.   term.setCursorPos(1,1)
  39.   term.setBackgroundColor(colors.white)
  40.   term.clear()
  41.   term.setBackgroundColor(colors.cyan)
  42.   term.setCursorPos(1,19)
  43.   term.clearLine()
  44. end
  45.    
  46. function monClicked()  
  47.   memo1()
  48.   memo2()
  49.   memo3()
  50.   memo4()
  51.   memo5()
  52.   drawTerm()
  53.   while true do
  54.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  55.     if xPos == 12 and yPos == 3 and note1 == 0 then
  56.       note1 = 1
  57.       click1()
  58.     elseif xPos == close1b and yPos == 3 and note1 == 1 then
  59.       note1 = 0
  60.       memo1()
  61.     elseif xPos == 12 and yPos == 5 and note2 == 0 then
  62.       note2 = 1
  63.       click2()
  64.     elseif xPos == close2b and yPos == 5 and note2 == 1 then
  65.       note2 = 0
  66.       memo2()
  67.     elseif xPos == 12 and yPos == 7 and note3 == 0 then
  68.       note3 = 1
  69.       click3()
  70.     elseif xPos == close3b and yPos == 7 and note3 == 1 then
  71.       note3 = 0
  72.       memo3()  
  73.     elseif xPos == 12 and yPos == 9 and note4 == 0 then
  74.       note4 = 1
  75.       click4()
  76.     elseif xPos == close4b and yPos == 9 and note4 == 1 then
  77.       note4 = 0
  78.       memo4()
  79.     elseif xPos == 12 and yPos == 11 and note5 == 0 then
  80.       note5 = 1
  81.       click5()
  82.     elseif xPos == close5b and yPos == 11 and note5 == 1 then
  83.       note5 = 0
  84.       memo5()
  85.     end
  86.   end
  87. end
  88.    
  89. function background()
  90.   mon.setBackgroundColor(colors.cyan)
  91.   mon.setCursorPos(1,1)
  92.   mon.clearLine()
  93.   mon.setTextColor(colors.white)
  94.   mon.setCursorPos(centretxt, 1)
  95.   mon.write("Memos")
  96. end
  97.  
  98.  
  99.  
  100. function memo1()
  101.   mon.setCursorPos(2,3)
  102.   mon.setTextColor(colors.red)
  103.   mon.setBackgroundColor(colors.white)
  104.   mon.clearLine()
  105.   mon.write("Add Memo")
  106.   mon.setCursorPos(11,3)
  107.   mon.setBackgroundColor(colors.green)
  108.   mon.setTextColor(colors.white)
  109.   mon.write(" X ")
  110. end
  111.  
  112. function click1()
  113.   mon.setCursorPos(2,3)
  114.   mon.setBackgroundColor(colors.white)
  115.   mon.clearLine()
  116.   mon.setTextColor(colors.red)
  117.   mon.write("Type message into computer")
  118.   term.setCursorPos(2,19)
  119.   input1 = read()
  120.   ilength = string.len(input1)
  121.   if ilength > width-11 then
  122.        term.setCursorPos(1,1)
  123.     term.setBackgroundColor(colors.white)
  124.     term.setTextColor(colors.red)
  125.     print("This memo is too long for your monitor. Add extra monitors, or shorten your memo")
  126.     sleep(3)
  127.     note1 = 0
  128.     memo1()
  129.   else
  130.     drawTerm()
  131.     mon.setCursorPos(2,3)
  132.     mon.clearLine()
  133.     mon.write("1) "..input1)
  134.     close1a = width - 3
  135.     close1b = width - 2
  136.     mon.setCursorPos(close1a, 3)
  137.     mon.setBackgroundColor(colors.red)
  138.     mon.setTextColor(colors.white)
  139.     mon.write(" X ")
  140.   end
  141. end
  142.  
  143. function memo2()
  144.   mon.setCursorPos(2,5)
  145.   mon.setTextColor(colors.red)
  146.   mon.setBackgroundColor(colors.white)
  147.   mon.clearLine()
  148.   mon.write("Add Memo")
  149.   mon.setCursorPos(11,5)
  150.   mon.setBackgroundColor(colors.green)
  151.   mon.setTextColor(colors.white)
  152.   mon.write(" X ")
  153. end
  154.  
  155. function click2()
  156.   mon.setCursorPos(2,5)
  157.   mon.setBackgroundColor(colors.white)
  158.   mon.clearLine()
  159.   mon.setTextColor(colors.red)
  160.   mon.write("Type message into computer")
  161.   input1 = read()
  162.   ilength = string.len(input1)
  163.   if ilength > width-11 then
  164.     term.setCursorPos(1,1)
  165.     term.setBackgroundColor(colors.white)
  166.     term.setTextColor(colors.red)
  167.     print("This memo is too long for your monitor. Add extra monitors, or shorten your memo")
  168.     sleep(3)
  169.     note2 = 0
  170.     memo2()
  171.   else
  172.     drawTerm()
  173.     mon.setCursorPos(2,5)
  174.     mon.clearLine()
  175.     mon.write("2) "..input1)
  176.     close2a = width - 3
  177.     close2b = width - 2
  178.      mon.setCursorPos(close2a, 5)
  179.     mon.setBackgroundColor(colors.red)
  180.      mon.setTextColor(colors.white)
  181.     mon.write(" X ")
  182.   end
  183. end
  184.    
  185. function memo3()
  186.   mon.setCursorPos(2,7)
  187.   mon.setTextColor(colors.red)
  188.   mon.setBackgroundColor(colors.white)
  189.   mon.clearLine()
  190.   mon.write("Add Memo")
  191.   mon.setCursorPos(11,7)
  192.   mon.setBackgroundColor(colors.green)
  193.   mon.setTextColor(colors.white)
  194.   mon.write(" X ")
  195. end
  196.  
  197. function click3()
  198.   mon.setCursorPos(2,7)
  199.   mon.setBackgroundColor(colors.white)
  200.   mon.clearLine()
  201.   mon.setTextColor(colors.red)
  202.   mon.write("Type message into computer")
  203.   input1 = read()
  204.   ilength = string.len(input1)
  205.   if ilength > width-11 then
  206.     term.setCursorPos(1,1)
  207.     term.setBackgroundColor(colors.white)
  208.     term.setTextColor(colors.red)
  209.     print("This memo is too long for your monitor. Add extra monitors, or shorten your memo")
  210.     sleep(3)
  211.     note3 = 0
  212.     memo3()
  213.   else
  214.     drawTerm()
  215.     mon.setCursorPos(2,7)
  216.     mon.clearLine()
  217.     mon.write("3) "..input1)
  218.     close3a = width - 3
  219.     close3b = width - 2
  220.     mon.setCursorPos(close3a, 7)
  221.     mon.setBackgroundColor(colors.red)
  222.     mon.setTextColor(colors.white)
  223.     mon.write(" X ")
  224.   end
  225. end  
  226.  
  227. function memo4()
  228.   mon.setCursorPos(2,9)
  229.   mon.setTextColor(colors.red)
  230.   mon.setBackgroundColor(colors.white)
  231.   mon.clearLine()
  232.   mon.write("Add Memo")
  233.   mon.setCursorPos(11,9)
  234.   mon.setBackgroundColor(colors.green)
  235.   mon.setTextColor(colors.white)
  236.   mon.write(" X ")
  237. end
  238.  
  239. function click4()
  240.   mon.setCursorPos(2,9)
  241.   mon.setBackgroundColor(colors.white)
  242.   mon.clearLine()
  243.   mon.setTextColor(colors.red)
  244.   mon.write("Type message into computer")
  245.   input1 = read()
  246.   ilength = string.len(input1)
  247.   if ilength > width-11 then
  248.     term.setCursorPos(1,1)
  249.     term.setBackgroundColor(colors.white)
  250.     term.setTextColor(colors.red)
  251.     print("This memo is too long for your monitor. Add extra monitors, or shorten your memo")
  252.     sleep(3)
  253.     note4 = 0
  254.     memo4()
  255.   else
  256.     drawTerm()
  257.      mon.setCursorPos(2,9)
  258.     mon.clearLine()
  259.     mon.write("4) "..input1)
  260.     close4a = width - 3
  261.     close4b = width - 2
  262.     mon.setCursorPos(close4a, 9)
  263.     mon.setBackgroundColor(colors.red)
  264.     mon.setTextColor(colors.white)
  265.     mon.write(" X ")
  266.   end
  267. end
  268.  
  269. function memo5()
  270.   mon.setCursorPos(2,11)
  271.   mon.setTextColor(colors.red)
  272.   mon.setBackgroundColor(colors.white)
  273.   mon.clearLine()
  274.   mon.write("Add Memo")
  275.   mon.setCursorPos(11,11)
  276.   mon.setBackgroundColor(colors.green)
  277.   mon.setTextColor(colors.white)
  278.   mon.write(" X ")
  279. end
  280.  
  281. function click5()
  282.   mon.setCursorPos(2,11)
  283.   mon.setBackgroundColor(colors.white)
  284.   mon.clearLine()
  285.   mon.setTextColor(colors.red)
  286.   mon.write("Type message into computer")
  287.   input1 = read()
  288.   ilength = string.len(input1)
  289.   if ilength > width-11 then
  290.     term.setCursorPos(1,1)
  291.     term.setBackgroundColor(colors.white)
  292.     term.setTextColor(colors.red)
  293.     print("This memo is too long for your monitor. Add extra monitors, or shorten your memo")
  294.     sleep(3)
  295.     note5 = 0
  296.     memo5()
  297.   else
  298.     drawTerm()
  299.     mon.setCursorPos(2,11)
  300.     mon.clearLine()
  301.     mon.write("5) "..input1)
  302.     close5a = width - 3
  303.     close5b = width - 2
  304.     mon.setCursorPos(close5a, 11)
  305.     mon.setBackgroundColor(colors.red)
  306.     mon.setTextColor(colors.white)
  307.     mon.write(" X ")
  308.   end
  309. end
  310.    
  311. --[Declarations of Functions]--    
  312. test()
  313. background()
  314. monClicked()
Add Comment
Please, Sign In to add comment