Posted 26 July 2013 - 04:04 AM
An advanced than you to all the helpful lua geniuses out there for taking the time to help us noobs!
Basically, I modified redpulse so that you can select multiple sides to pulse. Also gives an option to loop forever.
It works perfectly but I can't help but thinking there was a much easier way to do this. Anyone have any ideas? I'm fairly new to lua.
Basically, I modified redpulse so that you can select multiple sides to pulse. Also gives an option to loop forever.
It works perfectly but I can't help but thinking there was a much easier way to do this. Anyone have any ideas? I'm fairly new to lua.
local tArgs = { ... }
local nSides = tonumber(tArgs[1])
if not nSides then
print("Usage: pulser <number of sides> <count> <period>")
return
end
local nCount = tonumber(tArgs[2]) or 1
local nPeriod = tonumber(tArgs[3]) or 1
function sSides()
if nSides == 1 then
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
sSide2 = sSide1
sSide3 = sSide1
sSide4 = sSide1
sSide5 = sSide1
sSide6 = sSide1
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 2 then
term.clear()
term.setCursorPos(1,1)
term.clear()
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
sSide3 = sSide1
sSide4 = sSide1
sSide5 = sSide1
sSide6 = sSide1
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 3 then
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
sSide4 = sSide1
sSide5 = sSide1
sSide6 = sSide1
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 4 then
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide4 = io.read()
sSide5 = sSide1
sSide6 = sSide1
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 5 then
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide4 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide5 = io.read()
sSide6 = sSide1
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 6 then
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide4 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide5 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide6 = io.read()
sSide7 = sSide1
sSide8 = sSide1
elseif nSides == 7 then
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide4 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide5 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide6 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide7 = io.read()
sSide8 = sSide1
elseif nSides == 8 then
term.setCursorPos(1,1)
print("What side?")
sSide1 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide2 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide3 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide4 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide5 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide6 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide7 = io.read()
term.clear()
term.setCursorPos(1,1)
print("What side?")
sSide8 = io.read()
elseif nSides > 8 then
term.clear()
term.setCursorPos("Invalid number of sides!")
sleep(0.5)
os.reboot()
end
end
function pulser()
redstone.setOutput( sSide1, true )
redstone.setOutput( sSide2, true )
redstone.setOutput( sSide3, true )
redstone.setOutput( sSide4, true )
redstone.setOutput( sSide5, true )
redstone.setOutput( sSide6, true )
redstone.setOutput( sSide7, true )
redstone.setOutput( sSide8, true )
sleep( nPeriod / 2 )
redstone.setOutput( sSide1, false )
redstone.setOutput( sSide2, false )
redstone.setOutput( sSide3, false )
redstone.setOutput( sSide4, false )
redstone.setOutput( sSide5, false )
redstone.setOutput( sSide6, false )
redstone.setOutput( sSide7, false )
redstone.setOutput( sSide8, false )
sleep( nPeriod / 2 )
end
sSides()
if nCount == 0 then
while true do
pulser()
end
else
for x = 1,nCount do
pulser()
end
end