Advertisement
Enstroe

BB_Peripherals

Jan 24th, 2022 (edited)
960
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------------------------
  2. -- # Title : Base Butler - Peripherals Handler  
  3. ------------------------------------------------------
  4.  
  5. os.loadAPI("BaseButler/interaction.lua")
  6.  
  7. -- Initialises a connected Monitor
  8. function InitialiseMonitor(monitor)    --Called only by AssertMonitorPresent()
  9.    
  10.     if (monitor ~= nil) then
  11.         monitor.setBackgroundColour(colors.gray)
  12.         monitor.setTextColour(1)
  13.         monitor.setTextScale(1)
  14.         monitor.setCursorPos(1,1)
  15.         monitor.clear()
  16.     end
  17.  
  18.     return monitor
  19. end
  20.  
  21.  
  22. -- Asserts if a Monitor is connected, relaying a relative message if this is a new change and initialising a Monitor it was just connected
  23. function AssertMonitorPresent(monitor) -- Called in MainProcess()
  24.  
  25.     local monitorWasPresent = (monitor ~= nil)
  26.     monitor = peripheral.find("monitor")
  27.     local monitorPresent = (monitor ~= nil)
  28.  
  29.     if (monitorPresent == true) then
  30.        
  31.         if (monitorWasPresent == false) then
  32.             interaction.ComputerLine("Monitor has been connected!", monitor)
  33.             monitor = InitialiseMonitor()
  34.         end
  35.     else
  36.        
  37.         if (monitorWasPresent == true) then
  38.             interaction.ErrorLine("Monitor has been disconnected!", monitor)
  39.         end
  40.     end
  41.  
  42.     return monitor
  43. end
  44.  
  45.  
  46. -- Asserts if a ChatBox is connected, relaying a relative message if this is a new change and initialising a ChatBox it was just connected
  47. function AssertChatBoxPresent(chatBox) -- Called in MainProcess()
  48.  
  49.     local chatBoxWasPresent = (chatBox ~= nil)
  50.     chatBox = peripheral.find("chatBox")
  51.     local chatBoxPresent = (chatBox ~= nil)
  52.  
  53.     if (chatBoxPresent == true) then
  54.        
  55.         if (chatBoxWasPresent == false) then
  56.             interaction.ComputerLine("ChatBox has been connected!", monitor)
  57.             -- InitialiseChatBox() -- No such function - may be in future
  58.         end
  59.     else
  60.        
  61.         if (chatBoxWasPresent == true) then
  62.             interaction.ErrorLine("ChatBox has been disconnected!", monitor)
  63.         end
  64.     end
  65.  
  66.     return chatBox
  67. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement