Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lua script by Andrakon
- -- Written to make using Redpower Bundles easy!
- -- Version 1.2
- -- use help() to read the directions for use.
- -- Sides are defined with "back" or "left"
- -- Uses standard color names such as "red" or "lightBlue"
- -- Works with american and europeon versions of gray/grey
- -- Make sure to include os.loadAPI ("bundleAPI") in your program!
- -- sets up the tabletracker array that keeps track off all the sides and colors that are on
- local sides = 6
- local colors = 16
- local tabletracker = {}
- local sidenumbers = {}
- local writeside = 0
- local writecolor = 0
- for i=1,sides do
- tabletracker[i] = {}
- for j=1,colors do
- tabletracker[i][j] = 0
- end
- end
- -- Version number
- function getVersion()
- return 1.1
- end
- -- built in help page
- function help()
- term.clear()
- term.setCursorPos(1,1)
- write('on("side", "color") turns ON the selected color on the selected side.\n')
- write('off("side", "color")turns OFF the selected color on the selected side.\n')
- write('toggle("side", "color")Toggles the selected color on the selected side.\n')
- write('getOutput("side", "color") returns a 0 or 1 depending on what has been turned off or on.\n')
- write('getInput("side", "color") returns a 0 or 1, reads an input or output as on.\n')
- write('resetAll() turns off all colors on all sides.\n')
- write('resetSide("side") turns off all colors on selected side.\n')
- write('resetColor("color") turns off all of selected color on all sides.\n')
- write('Uses standard color names such as "red" or "lightBlue"')
- write('Works with american and europeon versions of gray/grey.')
- write('help2() second page of help')
- end
- function help2()
- term.clear()
- term.setCursorPos(1,1)
- write('getVersion() returns the version of the API')
- write('pulse("side", "color", time) toggles the side and color for the specified time for example 1 for one second or 0.5 for 1/2 a second.')
- end
- -- checks for valid sides
- local validSides = {}
- local function sideCheck(sSide)
- for n,sSide in ipairs( rs.getSides() ) do
- validSides[ sSide ] = true
- end
- if type( sSide ) ~= "string" then
- error( "side string expected" )
- end
- if not validSides[sSide] then
- error( "Invalid side" )
- end
- end
- --read from the tabletracker array, write to the sidenumbers table, and turn everything off or on
- local function update()
- for i=1,sides do
- sidenumbers[i] = 0
- end
- for i=1,sides do
- for j=1,colors do
- if tabletracker[i][j] == 1 then
- if (2^(j-1)) == 0 then
- sidenumbers[i] = sidenumbers[i]+1
- else
- sidenumbers[i] = sidenumbers[i]+(2^(j-1))
- end
- end
- end
- end
- redstone.setBundledOutput("front", sidenumbers[1])
- redstone.setBundledOutput("back", sidenumbers[2])
- redstone.setBundledOutput("left", sidenumbers[3])
- redstone.setBundledOutput("right", sidenumbers[4])
- redstone.setBundledOutput("top", sidenumbers[5])
- redstone.setBundledOutput("bottom", sidenumbers[6])
- end
- local function tablesort(side, color)
- if type( color ) ~= "string" then
- error( "color string expected" )
- end
- -- sort sides and reformat for table usage
- if side == "front" then writeside = 1 end
- if side == "back" then writeside = 2 end
- if side == "left" then writeside = 3 end
- if side == "right" then writeside = 4 end
- if side == "top" then writeside = 5 end
- if side == "bottom" then writeside = 6 end
- -- incase of mixup
- if side == "up" then writeside = 5 end
- if side == "down" then writeside = 6 end
- -- sort colors and reformat for table usage
- if color == "white" then writecolor = 1
- elseif color == "orange" then writecolor = 2
- elseif color == "magenta" then writecolor = 3
- elseif color == "lightBlue" then writecolor = 4
- elseif color == "yellow" then writecolor = 5
- elseif color == "lime" then writecolor = 6
- elseif color == "pink" then writecolor = 7
- elseif color == "gray" then writecolor = 8
- elseif color == "lightGray" then writecolor = 9
- elseif color == "cyan" then writecolor = 10
- elseif color == "purple" then writecolor = 11
- elseif color == "blue" then writecolor = 12
- elseif color == "brown" then writecolor = 13
- elseif color == "green" then writecolor = 14
- elseif color == "red" then writecolor = 15
- elseif color == "black" then writecolor = 16
- -- incase of mixup
- elseif color == "lightblue" then writecolor = 4
- elseif color == "grey" then writecolor = 8
- elseif color == "lightGrey" then writecolor = 9
- elseif color == "lightgrey" then writecolor = 9
- else
- error( "invalid color" )
- end
- end
- function on(aside,acolor)
- sideCheck(aside)
- tablesort(aside,acolor)
- if tabletracker[writeside][writecolor] == 0 then
- tabletracker[writeside][writecolor] = 1
- update()
- end
- end
- function off(aside,acolor)
- sideCheck(aside)
- tablesort(aside,acolor)
- if tabletracker[writeside][writecolor] == 1 then
- tabletracker[writeside][writecolor] = 0
- update()
- end
- end
- function toggle(aside,acolor)
- sideCheck(aside)
- tablesort(aside,acolor)
- if tabletracker[writeside][writecolor] == 0 then
- tabletracker[writeside][writecolor] = 1
- update()
- else
- tabletracker[writeside][writecolor] = 0
- update()
- end
- end
- function getOutput(aside, acolor)
- sideCheck(aside)
- tablesort(aside,acolor)
- return tabletracker[writeside][writecolor]
- end
- function resetAll()
- for i=1,sides do
- for j=1,colors do
- tabletracker[i][j] = 0
- end
- end
- update()
- end
- function resetSide(aside)
- sideCheck(aside)
- tablesort(aside, "white")
- for j=1,colors do
- tabletracker[writeside][j] = 0
- end
- update()
- end
- function resetColor(acolor)
- tablesort("front", acolor)
- for i=1,sides do
- tabletracker[i][writecolor] = 0
- end
- update()
- end
- function getInput(aside, acolor)
- sideCheck(aside)
- tablesort("front", acolor)
- writecolor = 2^(writecolor-1)
- if writecolor == 0 then
- writecolor = 1
- end
- return redstone.testBundledInput(aside,writecolor)
- end
- function pulse(aside, acolor, time)
- toggle(aside, acolor)
- sleep(time)
- toggle(aside, acolor)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement