Posted 04 November 2012 - 08:49 AM
A collection of my useful bits of code, usually from posting them in Ask a Pro topics.
This function sets a bundled color output to a given state without affecting any of the other color output on that side.
This function toggles a bundled output color on a side without affecting any other bundled outputs on that side.
The rednet distance expression is this:
A Lua function to find the rednet distance for a given height (and optional minimum and maximum distances and world height):
This function sets a bundled color output to a given state without affecting any of the other color output on that side.
function setBundledColor(side, color, state)
if state then
if not colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end
else
if colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
end
end
end
This function toggles a bundled output color on a side without affecting any other bundled outputs on that side.
function toggleBundledColor(side, color)
rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end
The rednet distance expression is this:
minRange + (position.yCoord - 96.0) * ((maxRange - minRange) / ((world.getHeight() - 1) - 96.0))
A Lua function to find the rednet distance for a given height (and optional minimum and maximum distances and world height):
function findRednetRange(height, _min, _max, _worldHeight)
if type(height) ~= "number" then return end
min = _min or 64
max = _max or 384
worldHeight = _worldHeight or 256
return min + (height - 96.0) * ((max - min) / ((worldHeight - 1) - 96.0))
end