Enstroe

BB_Interaction

Jan 24th, 2022 (edited)
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.94 KB | None | 0 0
  1. ------------------------------------------------------
  2. -- # Title : Base Butler - Interaction Functions  
  3. ------------------------------------------------------
  4.  
  5. ---------------------------
  6. -- # Member Variable Declarations
  7. ---------------------------
  8.  
  9. Scale = 1
  10.  
  11. PosX = Scale
  12. PosY = Scale
  13.    
  14.  
  15.  
  16. -- Outputs any given text, and if specified, any give text type to the computer and a connected Monitor
  17. function WriteLine(monitor, text, typeText) -- monitor essential so place at beginning
  18.  
  19.     print("cursorPosY = " .. PosY)
  20.  
  21.     if (text == nil) then
  22.         print("Error - WriteLine(monitor, text) - text == nil")
  23.     else
  24.  
  25.         -- Outputs to computer
  26.         if (typeText == nil) then
  27.             print(text)
  28.         else
  29.             print(typeText .. " - " .. text)
  30.         end    
  31.  
  32.         -- Outputs to the Monitor if one is present
  33.         if (monitor ~= nil) then
  34.  
  35.             monitor.write(text)        
  36.             monitor.setCursorPos(PosX, PosY)
  37.             PosY = PosY + Scale
  38.         end
  39.     end
  40. end
  41.  
  42.  
  43. -- Outputs any given text, and if specified, any give text type to the computer and a connected ChatBox
  44. function SendChat(chatBox, text, prefix) -- chatBox essential so place at beginning
  45.  
  46.     if (text == nil) then
  47.         print("Error - SendChat(text) - text == nil")
  48.     else
  49.         -- Outputs to the Monitor if one is present
  50.         if (chatBox ~= nil) then
  51.             chatBox.sendMessage(text, prefix)
  52.             print("Sent to chat : " .. text)
  53.             os.sleep(1)
  54.         end
  55.     end
  56. end
  57.  
  58.  
  59. -- Outputs a new line to the computer
  60. function NewLine(monitor)
  61.     WriteLine(monitor, "")
  62. end
  63.  
  64.  
  65. -- Outputs a formatted message from the program to the computer and a connected Monitor
  66. function ComputerLine(text, monitor, chatBox) -- peripherals allowed to be null so place at end
  67.    
  68.     if (monitor ~= nil) then
  69.         monitor.setTextColour(colors.lightBlue)
  70.     end
  71.  
  72.     WriteLine(monitor, text, "Computer")
  73.     SendChat(chatBox, text, CommandPhrase)
  74.  
  75. end
  76.  
  77.  
  78. -- Outputs a formatted message from chat to the computer and a connected Monitor
  79. function ChatLine(text, monitor) -- monitor allowed to be null so place at end
  80.    
  81.     if (monitor ~= nil) then
  82.         monitor.setTextColour(colors.white)
  83.     end
  84.  
  85.     WriteLine(monitor, text, "Chat")
  86.  
  87. end
  88.  
  89.  
  90. -- Outputs a formatted error message to the computer and a connected Monitor
  91. function ErrorLine(text, monitor) -- monitor allowed to be null so place at end
  92.    
  93.     if (monitor ~= nil) then
  94.         monitor.setTextColour(colors.red)
  95.     end
  96.    
  97.     WriteLine(monitor, text, "Error")
  98.  
  99. end
  100.  
  101.  
  102. -- Refreshes Display
  103. function RefreshDisplay(monitor)
  104.    
  105.     if (monitor ~= nil) then
  106.  
  107.         local monitorWidth = nil
  108.         local monitorHeight = nil
  109.         monitorWidth, monitorHeight = Monitor.getSize()
  110.  
  111.         if (PosY > monitorHeight) then
  112.             monitor.scroll(PosY - monitorHeight)      
  113.         end
  114.     end
  115.  
  116. end
Add Comment
Please, Sign In to add comment