Advertisement
milkshake

Untitled

Jun 17th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. -- Custom monitor program
  2. -- Works with: Advanced Computer & Monitor
  3. -- Environment Tested: Minecraft 1.6.4 Computer Craft version 1.5
  4. -- By RCMilkshakebunny @ www.rcftb.eu
  5.  
  6. -- ##########################
  7. -- DEFINE VARIABLES -- BEGIN
  8.  
  9. -- Define peripheral monitor side
  10. m = peripheral.wrap("top")
  11.  
  12. -- DEFINE VARIABLES -- END
  13. -- ##########################
  14.  
  15. -- ##########################
  16. -- FUNCTIONS - BEGIN
  17.  
  18. -- set the cursor position on the monitor ready to write
  19. -- in this case 1,1 means the first line at the first character. so for western based code that would be TOP,LEFT
  20. -- if we were to put (5,10) then the cursor would begin at the 5th line down and the 10th character position in from the left
  21. -- in this case the function requires the value to be given in the call
  22. function cursor(p1,p2)
  23.   m.setCursorPos(p1,p2)
  24. end
  25.  
  26. -- clear any content on the monitor function
  27. function clearMon()
  28.   m.clear()
  29. end
  30.  
  31. -- set text color function
  32. function textColor(setTo)
  33. -- set the color the text will be
  34. -- in this case blue
  35. -- the choices: white | orange | magenta | lightBlue | yellow | lime | pink | gray
  36. --   contd.. | lightGray | cyan | purple | blue | brown | green | red | black
  37. -- you can also reference colors by a 'decimal value' without the requirement of the use of 'colors'
  38. -- an example of referencing a color for text by decimal is
  39. -- m.setTextColor(512) and this would produce the same result as m.setTextColor(colors.cyan)
  40. -- m.setTextColor(colors.blue) -- << basic usage
  41.   m.setTextColor(setTo)-- << dynamic usage
  42. end
  43.  
  44. -- write to monitor function
  45. function monitorWrite(txt)
  46.   m.write(txt)
  47. end
  48.  
  49. -- monitor set new line
  50. function nl()
  51.   local _,cY= m.getCursorPos()
  52.   m.setCursorPos(1,cY+1)
  53. end
  54.  
  55. --initialise monitor function
  56. function mInit()
  57.   clearMon()
  58.   cursor(1,1)
  59.   textColor(512)
  60. end
  61.  
  62. -- ##########################
  63. -- TERMINAL FUNCTIONS -- BEGIN
  64.  
  65. -- clears terminal
  66. function clearTerm()
  67.   term.clear()
  68. end
  69.  
  70. -- writes to the terminal
  71. function writeTerm(termtext)
  72.   term.write(termtext)
  73. end
  74.  
  75. -- set terminal cursor position -- Dynamic
  76. function termCursor(p1,p2)
  77.   term.setCursorPos(p1,p2)
  78. end
  79.  
  80. -- terminal set new line
  81. function term_nl()
  82.   local _,cY= term.getCursorPos()
  83.   term.setCursorPos(1,cY+1)
  84. end
  85.  
  86. -- TERMINAL FUNCTIONS -- END
  87. -- ##########################
  88.  
  89. -- the program function
  90. function program()
  91.  
  92. -- ##########################
  93. -- PROGRAM OUTPUT - BEGIN
  94.  
  95.   clearTerm()
  96.   termCursor(1,1)
  97.   writeTerm("Program Running")
  98.   term_nl()
  99.  
  100. -- Test Output to monitor
  101.   a = monitorWrite("Testing")
  102.   if a then
  103.     writeTerm("Monitor write completed")
  104.   else
  105.     writeTerm("Error")
  106.   end
  107.  
  108. -- PROGRAM OUTPUT - END
  109. -- ##########################
  110. end
  111.  
  112. -- FUNCTIONS -- END
  113. -- ##########################
  114.  
  115. -- ############################################################
  116. -- ############################################################
  117.  
  118. -- ##########################
  119. -- SEQUENCE -- BEGIN
  120.  
  121. mInit()
  122. program()
  123.  
  124. -- SEQUENCE -- END
  125. -- ##########################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement