Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local validSides = {top = true, bottom = true, left = true, right = true, front = true, back = true}
- local validPow2 = {[1] = true, [2] = true, [4] = true, [8] = true, [16] = true, [32] = true, [64] = true, [128] = true,
- [256] = true, [512] = true, [1024] = true, [2048] = true,
- [4096] = true, [8192] = true, [16384] = true, [32768] = true }
- function toggleBundleColor(sSide, ...)
- -- Provide helpful error messages
- if type(sSide) ~= "string" then
- error("(toggleBundleColor): Bad argument (sSide, 1): Expected string, got " .. type(sSide), 2)
- end
- if not validSides[sSide] then
- error("(toggleBundleColor): Unrecognied side: " .. sSide, 2)
- end
- -- Retrieve the colors outside of the loop
- local nColors = rs.getBundledOutput(sSide)
- -- Loop through all the extra arguments
- for i, v in ipairs(arg) do
- -- Error messages, again.
- local sColor = v
- local nColor = colors[sColor]
- if type(sColor) == "number" then
- nColor = sColor
- end
- if not validPow2[nColor] then
- error("(toggleBundleColor): Bad argument (color, " .. i .. "): Unrecognized color.", 2)
- end
- -- Modify the color
- nColors = bit.bxor(nColors, nColor) -- This will toggle the 'bit' of color we have.
- end
- rs.setBundledOutput(sSide, nColors) -- Change the colors.
- return nColors -- Return what the changed colors are.
- end
Advertisement
Add Comment
Please, Sign In to add comment