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 ON MY PASTEBIN, DO NOT DOWNLOAD THIS ALONE! IT WONT WORK BY ITSELF.
- Installer:
- In a CC Computer (Advanced only!):
- pastebin get 5Tfpzcbz installer
- From pastebin site:
- http://pastebin.com/5Tfpzcbz
- Description:
- This program allows for (slightly) custom buttons that control redstone using bundled cable (or a similar item)
- When it first starts, it will ask you to add buttons
- To use it, run the installer - That will tell you what to do
- Q:What is this?
- A:See description
- Q:Im confused
- A:I don't have a video yet, so you'll have to figure it out :P
- Q:Auto-Update?
- A:Not yet, and not planned
- Q:Where do I report bugs?
- A:I don't have a place for this program. If you find any then you can message me on
- youtube, but I most likely won't do anything because version 3.0 is comming soon.
- VERSIONS:
- NOTE:I am still adding to the program! This is just to get out the changes that work so far.
- |2.0| <-- This program
- 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 = "2.0"
- local outputNames = {}
- local currentOut = 0
- local monSide
- local cableSide = "right"
- local buttons = {}
- local tLines = {}
- cReference = {
- ["colors.white"] = 1,
- ["colors.orange"] = 2,
- ["colors.magenta"] = 4,
- ["colors.lightBlue"] = 8,
- ["colors.yellow"] = 16,
- ["colors.lime"] = 32,
- ["colors.pink"] = 64,
- ["colors.gray"] = 128,
- ["colors.lightGray"] = 256,
- ["colors.cyan"] = 512,
- ["colors.purple"] = 1024,
- ["colors.blue"] = 2048,
- ["colors.brown"] = 4096,
- ["colors.green"] = 8192,
- ["colors.red"] = 16384,
- ["colors.black"] = 32768
- }
- --Functions--
- function clear() shell.run("clear") end
- function cp(...) term.setCursorPos(...) end
- function tc(...) term.setTextColor(...) end
- function bc(...) term.setBackgroundColor(...) end
- function w(...) term.write(...) 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)
- w(text)
- end
- function check(color)
- for a,b in pairs(cReference) do
- if a == color then
- return true
- end
- end
- return false
- end
- function setup()
- clear()
- print("Welcome to RedstoneControl Setup")
- print("How many buttons? (1-5)")
- while true do
- event,p1 = os.pullEvent("char")
- if tonumber(p1) > 0 and tonumber(p1) < 6 then
- number = p1
- break
- end
- end
- f = fs.open("/ARC/config","w")
- for i = 1, number do
- print("Enter the name of button "..i)
- print("Works best when less than 8 characters")
- w("> ")
- repeat
- input1 = read()
- until input1 ~= nil
- while true do
- print("Enter color for button "..input1.." to activate")
- print("Format: 'colors.blue'")
- w("> ")
- repeat
- input2 = read()
- until input2 ~= nil
- if check(input2) then
- break
- else
- clear()
- tc(colors.red)
- print("Not a color")
- tc(colors.white)
- end
- end
- f.write(input1..[[=]]..input2.."\n")
- print("Added "..input1.." to config file")
- end
- f.close()
- print("Config saved")
- end
- function main() --Having this as a function allows error catching
- clear()
- print("Loading config...")
- buttons = {}
- f = fs.open("/ARC/config","r")
- local l = 0
- repeat
- l = l+1
- tLines[l] = f.readLine()
- until tLines[l] == nil
- f.close()
- local tempvar
- for i = 1, #tLines do
- tempvar = string.find(tLines[i],"=")
- if not tempvar then
- print("ERROR ERROR ERROR")
- print(tLines[i].." doesn't have an = sign!")
- sleep(1)
- print("One sec...")
- print("Config must be redone")
- shell.run("delete RedstoneControl/config")
- sleep(1)
- shell.run(shell.getRunningProgram())
- error("Program Self-Terminated")
- end
- bName = string.sub(tLines[i],1,tempvar-1)
- bColor = string.sub(tLines[i],tempvar+1)
- buttons[i] = {}
- buttons[i]["name"] = bName
- buttons[i]["color"] = cReference[bColor]
- buttons[i]["state"] = false
- print("Added button "..bName.." that activates color "..bColor)
- end
- print("Searching for monitors...")
- local mSides = {}
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "monitor" then
- print("Found monitor on "..b.." side")
- mSides[#mSides+1] = b
- end
- end
- if #mSides == 0 then
- error("No monitors. Try adding one.")
- elseif #mSides > 1 then
- print("More than 1 monitor detected...")
- print("Located on the following sides:")
- for a,b in pairs(mSides) do
- print(b)
- end
- error("Remove the extras...")
- else
- m = peripheral.wrap(mSides[1])
- m.setBackgroundColor(colors.black)
- m.clear()
- end
- print("Starting program...")
- print("Running. Use ctrl + t to stop")
- print("Log:")
- while true do --Main loop
- 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(" ",7))
- m.setCursorPos(1,i)
- m.write(buttons[i]["name"])
- end
- print("Waiting for event...")
- event,p1,p2,p3,p4 = os.pullEvent()
- w("Event:") print(event)
- if event == "monitor_touch" then
- term.write("Location:") print(p1)
- term.write("X:") term.write(p2) term.write(" Y:") print(p3)
- if p3 <= #buttons then
- for i = 1, #buttons do
- if i == p3 then
- buttons[i]["state"] = not buttons[i]["state"]
- if buttons[i]["state"] then
- print(currentOut)
- print(buttons[i]["color"])
- currentOut = currentOut + buttons[i]["color"]
- else
- currentOut = currentOut - buttons[i]["color"]
- end
- end
- end
- else
- print("Nope")
- end
- end
- print(" ")
- end
- end
- --Program--
- clear()
- print("Redstone Control "..version)
- print("Initialize...")
- print("Loading Config...")
- if not fs.exists("/ARC/config") then
- tc(colors.red)
- print("Missing file: config")
- tc(colors.white)
- print("Fixing...")
- f = fs.open("/ARC/config","w")
- f.close()
- end
- f = fs.open("/ARC/config","r")
- local firstLine = f.readLine()
- if firstLine == nil then
- f.close()
- tc(colors.red)
- print("Config file blank. Running setup...")
- tc(colors.white)
- sleep(2)
- setup()
- else
- f.close()
- end
- --Capture any errors
- state,err = pcall(function() main() end)
- if err then
- if string.find("Terminated",err) then
- print("User terminated the program")
- elseif string.find("Program Self-Terminated",err) then
- print("Program Self-Terminated")
- else
- tc(colors.red)
- print("CRITICAL ERROR:")
- print(err)
- tc(colors.white)
- end
- end
- --Cleanup
- f.close()
- if m then
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setCursorPos(1,1)
- m.write("Program")
- m.setCursorPos(1,2)
- m.write("termina-")
- m.setCursorPos(1,3)
- m.write("ted")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement