Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Coded by HPWebcamAble
- http://pastebin.com/u/HPWebcamAble
- WARNING! USE THE INSTALLER, DO NOT DOWNLOAD THIS ALONE! IT WONT WORK BY ITSELF.
- **********
- Installer
- **********
- In a CC Computer (Advanced only!):
- pastebin get pVyr7LjW installer
- From pastebin site:
- http://pastebin.com/pVyr7LjW
- **********
- Description
- **********
- This program allows for (slightly) custom buttons that control redstone using bundled cable (or a similar item)
- When it first starts, it will allow you to configure everything.
- If you are not familiar with bundled cable, look it up.
- **********
- FAQ
- **********
- Q:What is this?
- A:See description
- Q:Im confused
- A:http://youtu.be/o_mzKx-7dS0
- Q:How do I make buttons?
- A:Use the config editor program
- Q:Auto-Update?
- A:Not yet, and not planned
- Q:Where do I report bugs?
- A:On it's Youtube video
- http://youtu.be/o_mzKx-7dS0
- **********
- Program Version History
- **********
- |3.1| <-- This program
- Date: 9/12/2014
- Changes:
- -Support for ConfigEditor 1.1
- Bugs:
- -Debug is always shown, even when disabled
- -log sometimes goes off screen (in multiple ways)
- None of these break anything, it still works fine :)
- |3.0|
- Date:8/15/2014
- Changes:
- -Added a config editor gui
- -Smarter monitor support
- Bugs:
- -Debug always shows even when disabled
- -log has problem displaying
- *Program still works tho
- |2.0|
- Date: 8/5/2014
- Changes:
- -Redesigned code
- *Program now uses an installer
- *Creates a config file for the buttons
- *Buttons are a bit easier to set up
- -To redo, just delete the config file in the ARC directory
- Bugs:
- -None so far
- |1.0 (Release)|
- Date: Unknown
- Bugs:
- -Not super easy to set up
- *Does work though
- Installation:
- -This program
- -My button API
- ]]
- --Variables--
- local version = "3.1"
- local outputNames = {}
- local currentOut = 0
- local cableSide
- local buttons = {}
- local tLines = {}
- local doDebug = false
- w,h = term.getSize()
- local tLog = {}
- local logSev = {
- [1] = {
- "Info",
- "Warning",
- "Severe",
- "Debug",
- "End"
- },
- [2] = {
- colors.white,
- colors.orange,
- colors.red,
- colors.magenta,
- colors.red
- }
- }
- --Functions--
- function clear() shell.run("clear") end
- function tc(...) term.setTextColor(...) end
- function bc(...) term.setBackgroundColor(...) end
- function tw(...) term.write(...) end
- function cp(...) term.setCursorPos(...) end
- function printC(text,y)
- if not y then
- error("printC:No Y value specified")
- end
- cp(math.ceil(w/2-#tostring(text)/2),y)
- tw(text)
- end
- function log(text,sev)
- numLog = #tLog+1
- tLog[numLog] = {}
- if sev then
- if type(sev) ~= "number" then
- error("expected string,number of string,nil")
- end
- tLog[numLog]["text"] = text
- tLog[numLog]["sev"] = sev
- else
- tLog[numLog]["text"] = text
- tLog[numLog]["sev"] = 1
- end
- clear()
- tc(colors.white)
- printC("Advanced Redstone Control",1)
- printC("v"..version,2)
- term.setCursorPos(1,3)
- tw(string.rep("-",w))
- local hud = 3
- local space = h-hud
- if numLog <= space then
- for i = 1, numLog do
- cp(1,i+hud)
- tc(logSev[2][tLog[i]["sev"]])
- tw("["..logSev[1][tLog[i]["sev"]].."] "..tLog[i]["text"])
- print(" ")
- if tLog[i]["sev"] == 3 then
- error("end")
- end
- end
- else
- for i = 1, space do
- cp(1,i+hud)
- tc(logSev[2][tLog[i+numLog-space]["sev"]])
- tw("["..logSev[1][tLog[i+numLog-space]["sev"]].."] "..tLog[i+numLog-space]["text"])
- print(" ")
- if tLog[i+numLog-space]["sev"] == 3 then
- error("end")
- elseif tLog[i+numLog-space]["sev"] == 5 then
- error()
- end
- end
- end
- end
- function isColor(color)
- for a,b in pairs(colors) do
- if b == color then
- return true
- end
- end
- return false
- end
- function isSide(side)
- for a,b in pairs(rs.getSides()) do
- if b == side then
- return true
- end
- end
- return false
- end
- function main() --Having this as a function allows error catching
- if doDebug then
- log("Debugging enabled",2)
- end
- log("Loading Config...")
- --Read the config
- if not fs.exists("/ARC/config") then
- log("Config file missing, run config creator",3)
- end
- f = fs.open("/ARC/config","r")
- local l = 0
- repeat
- l = l+1
- tLines[l] = f.readLine()
- until tLines[l] == nil
- f.close()
- if tLines[1] ~= "This is the Advanced Redstone Control config file" or tLines[2] ~= "Do not change anything in it!" or tLines[3] ~= "Use the provided config editor" then
- --Quite an if statement right?
- log("Config is blank or incorrectly formated, run config creator",3)
- end
- --Wrap the monitor
- if peripheral.getType(tLines[4]) ~= "monitor" then
- log("Could not find monitor '"..tLines[1].."'",3)
- end
- m = peripheral.wrap(tLines[4])
- log("Monitor set to '"..tLines[4].."'")
- --Set the side of the bundled cable (or its equivalent)
- if not isSide(tLines[5]) then
- log("'"..tLines[5].."' is not a side, run config creator",3)
- end
- log("Bundled cable set to side "..tLines[5])
- cableSide = tLines[5]
- --Load the buttons
- local equalPos
- for i = 1, tLines[6] do
- c = i+6
- equalPos = string.find(tLines[c],"=")
- if not equalPos then
- log("Something is wrong with line "..c.." in the config file, run config creator",3)
- end
- bName = string.sub(tLines[c],1,equalPos-1)
- bColor = string.sub(tLines[c],equalPos+1)
- buttons[i] = {}
- buttons[i]["name"] = bName
- buttons[i]["color"] = bColor
- buttons[i]["state"] = false
- log("Added button "..bName.." that activates color "..bColor,4)
- end
- log("Buttons added")
- log("Program running. Use Ctrl+t to stop")
- --Main loop
- while true do
- mw,mh = m.getSize()
- m.setBackgroundColor(colors.black)
- m.clear()
- rs.setBundledOutput(cableSide,currentOut)
- for i = 1, #buttons do
- if buttons[i]["state"] then m.setBackgroundColor(colors.lime) else m.setBackgroundColor(colors.red) end
- m.setCursorPos(1,i)
- m.write(string.rep(" ",mw))
- m.setCursorPos(1,i)
- m.write(buttons[i]["name"])
- end
- log("Waiting for event...",4)
- event,p1,p2,p3,p4 = os.pullEvent()
- log("Event:"..event,4)
- if event == "monitor_touch" then
- log("Monitor:"..p1,4)
- log("X:"..p2.." Y:"..p3,4)
- if p3 <= #buttons then
- for i = 1, #buttons do
- if i == p3 then
- buttons[i]["state"] = not buttons[i]["state"]
- log("Button '"..buttons[i]["name"].."' toggled",4)
- if buttons[i]["state"] then
- currentOut = currentOut + buttons[i]["color"]
- else
- currentOut = currentOut - buttons[i]["color"]
- end
- log("Bundled output set to "..currentOut,4)
- end
- end
- end
- end
- end
- end
- --Program--
- --Capture any errors
- state,err = pcall(function() main() end)
- if err then
- if string.find(err,"Terminated") then
- log("User terminated the program",5)
- elseif string.find(err,"end") then
- log("Program stopped",5)
- else
- tc(colors.blue)
- print("CRITICAL ERROR:")
- print(err)
- tc(colors.white)
- end
- end
- --Cleanup
- if f then
- f.close()
- end
- if m then
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setCursorPos(1,1)
- m.write("Program")
- m.setCursorPos(1,2)
- m.write("Stopped")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement