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 eMCqJEBs installer
- From pastebin site:
- http://pastebin.com/eMCqJEBs
- **********
- Description
- **********
- This program allows the user to turn bundled cable on and off in a set order.
- 'Configs' are created with the 'Config Editor'. They are run with this program (Redstone Engine)
- 'Configs' contain 'Events'.
- Possible events:
- Sleep (In config: s<time>) - Makes the computer pause for the specified time
- Set (In config: =<color>) - Sets the output to the color
- Add (In config: +<color>) - Adds a color to the current output
- Remove (In config: -<color>) - Removes a color from the current output
- Type 're' to edit or run configs
- To run configs:
- (In console)
- re run <config name>
- (In a program)
- shell.run("re run <config name>")
- Cable may be attached to any side of the computer
- **********
- FAQ
- **********
- Q:What is this?
- A:See description
- Q:How does bundled/rednet cable work?
- A:Look it up. Probably best on youtube.
- Q:The bundled cable isn't attaching to the computer correctly/it doesnt work
- A:At this moment, you need to use ComputerCraft 1.5, not 1.6
- See http://pastebin.com/1XY12jQZ for more info
- Q:Im confused
- A:Here's a video! (Leave a comment with questions):
- http://youtu.be/zPvUVptSnro
- Q:Where do I report bugs?
- A:On its Youtube Video (Leave it as a comment):
- http://youtu.be/zPvUVptSnro
- **********
- Version
- **********
- |1.1| <--This program
- Date:10/4/14
- -Bug fixes
- *Output could be negative easily
- -Tweaked what it says when cable is still on after program finishes
- -Cleaned up code a bit
- |1.0 (Release)|
- Date: 9/28/14
- Date Format: MM/DD/YY
- **********
- Bugs
- **********
- None! (Yet)
- ]]
- --Variables--
- local actions = {}
- w,h = term.getSize()
- args = {...}
- if not output then output = 0 end
- --Functions--
- function color(txt,bck)
- if txt then
- term.setTextColor(txt)
- end
- if bck then
- term.setBackgroundColor(bck)
- end
- end
- function clear() shell.run("clear") 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
- tLenght = #tostring(text)
- local sStart = math.ceil(w/2-tLenght/2)
- local sEnd = sStart + tLenght
- cp(sStart,y)
- tw(text)
- return sStart,sEnd
- end
- function bar(backColor,height,text,textColor)
- cp(1,height)
- color(textColor,backColor)
- tw(string.rep(" ",w))
- printC(text,height)
- end
- function drawScreen()
- clear()
- bar(colors.white,1,"Redstone Engine",colors.black)
- color(colors.white,colors.black)
- printC("Current Output:"..output,7)
- printC("Current Action:"..action,9)
- printC("Events completed:"..completeEvents,11)
- printC("Events left:"..totalEvents-completeEvents,13)
- color(colors.red)
- printC("Errors:"..#errors,h)
- end
- function update(cOutput,cAction)
- if cOutput then
- output = cOutput
- sides = rs.getSides()
- for i = 1, #sides do
- rs.setBundledOutput(sides[i],cOutput)
- end
- end
- action = cAction
- if action ~= "Starting..." then completeEvents = completeEvents+1 end
- drawScreen()
- end
- --Program--
- clear()
- color(colors.red,colors.black)
- if #args ~= 1 then
- print("No config specified")
- return
- elseif not fs.isDir("/RED/configs") then
- print("configs directory is missing. Run installer again")
- return
- elseif not fs.exists("/RED/configs/"..args[1]) then
- print("Could not find config '"..args[1].."'")
- return
- end
- --Load config
- f = fs.open("/RED/configs/"..args[1],"r")
- if f then
- local l = 0
- repeat
- l = l+1
- actions[l] = f.readLine()
- until actions[l] == nil
- f.close()
- else
- color(colors.red,colors.black)
- print("Unable to open config '"..args[1].."'")
- return
- end
- totalEvents = #actions
- completeEvents = 0
- errors = {}
- update(nil,"Starting...")
- --Main loop (As a function for error catching)
- function main()
- for i = 1, #actions do
- drawScreen()
- firstChar = string.sub(actions[i],1,1)
- if firstChar == "s" then --Sleep
- sTime = tonumber(string.sub(actions[i],2))
- if not sTime then
- table.insert(errors,i)
- else
- update(nil,"Sleeping for "..sTime.." seconds...")
- sleep(sTime)
- end
- elseif firstChar == "+" then --Add
- addColor = tonumber(string.sub(actions[i],2))
- if not addColor then
- table.insert(errors,i)
- else
- update(output+addColor,"Color "..addColor.." added to output")
- end
- elseif firstChar == "-" then --Subtract
- subColor = tonumber(string.sub(actions[i],2))
- if not subColor then
- table.insert(errors,i)
- else
- update(output-subColor,"Color "..subColor.." removed from output")
- end
- elseif firstChar == "=" then --Set
- setColor = tonumber(string.sub(actions[i],2))
- if not setColor then
- table.insert(errors,i)
- else
- update(setColor,"Output set to "..setColor)
- end
- else
- table.insert(errors,i)
- end
- end
- end
- state,err = pcall(function() main() end)
- if err then
- if string.find(err,"Terminated") then
- bar(colors.white,1,"Terminated - Click to clear screen",colors.red)
- os.pullEvent("mouse_click")
- clear()
- else
- clear()
- printC("The program encountered a critical error:",1)
- cp(1,2)
- print(err)
- end
- else
- clear()
- color(colors.white)
- print("Finished config '"..args[1].."'")
- if #errors > 0 then
- print("Errors in config:"..#errors)
- end
- if output > 0 then
- print("Output is still on (color:"..output..")")
- end
- end
- --Cleanup
- if f then f.close() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement