Advertisement
Lobakus

[Lua] Expandable Button for Computercraft

Aug 20th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. -- pastebin get YmbkBRWU yourname
  2.  
  3. -- if you want to add this programm to the startup, then you have to write: edit startup   ,   shell.run("your name of the programm")  ,  push CTRLG or STRG save ,  then again CTRLG or STRG exit        /\ ADDED /\
  4.  
  5. -- if you want to changed somthing take the text and go to create new paste with(-out)  login then you can download this to computercraft per    pastebin get (your code)
  6. local cableSide = "left"  -- Or where ever your cable is. (rednet cable)
  7.  
  8. local mon = peripheral.wrap("top") -- Or where ever your colour monitor is.
  9. mon.setTextColor(colours.white)
  10. mon.setBackgroundColor(colours.black)
  11. mon.clear()
  12.  
  13. local xLen, yLen = mon.getSize()
  14.  
  15. local myEvent
  16.  
  17. -- Menu items.
  18. -- Add as desired, but don't exceed 16 entries.
  19. local switches = {
  20.    ["Me System"] = {colour = colours.white,  screenRow =  1},   -- can change name (it´s colour of rednet cable)
  21.    ["Laser Drills"] = {colour = colours.orange,  screenRow =  4},   -- can change name (__)
  22.    ["EnderQuarrys"]  = {colour = colours.magenta, screenRow = 8},   -- can change name    
  23.    ["UU Matter Production"]  = {colour = colours.lightBlue, screenRow = 12},    -- can change name
  24.    ["Extractor <1>"]  = {colour = colours.yellow, screenRow = 16},
  25.    ["Extractor <2>"]  = {colour = colours.lime, screenRow = 20},
  26.    ["Strom Item Tesseract"]  = {colour = colours.pink, screenRow = 24},  
  27.    ["Hydropneumatischeangel"]  = {colour = colours.gray, screenRow = 28}}
  28.  
  29. -- you can change this for more lever or rename this you have to change this     }   ,    and the lines (15)
  30.  
  31. -- Initial menu render:
  32. for key,value in pairs(switches) do
  33.    mon.setBackgroundColor(colours.black)
  34.    mon.setCursorPos(2,value.screenRow)
  35.    mon.write(key)
  36.    mon.setCursorPos(xLen-5,value.screenRow)
  37.    
  38.    if colours.test(rs.getBundledOutput(cableSide),value.colour) then
  39.      mon.setBackgroundColor(colours.green)
  40.      mon.write(" On  ")
  41.    else
  42.      mon.setBackgroundColor(colours.red)
  43.      mon.write(" Off ")
  44.    end
  45. end    
  46.  
  47. -- Main program loop.
  48. while true do
  49.    myEvent = {os.pullEvent("monitor_touch")}
  50.    
  51.    for key,value in pairs(switches) do if myEvent[4] == value.screenRow then
  52.      mon.setCursorPos(xLen-5,value.screenRow)
  53.  
  54.      if not colours.test(rs.getBundledOutput(cableSide),value.colour) then
  55.        mon.setBackgroundColor(colours.green)
  56.        mon.write(" On  ")
  57.        rs.setBundledOutput(cableSide,colours.combine(rs.getBundledOutput(cableSide),value.colour))
  58.      else
  59.        mon.setBackgroundColor(colours.red)
  60.        mon.write(" Off ")
  61.        rs.setBundledOutput(cableSide,colours.subtract(rs.getBundledOutput(cableSide),value.colour))
  62.      end
  63.      
  64.      break
  65.    end end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement