animate.lua

by hugeblank
584 days agolua
COPY
1
if not fs.exists("lamps.txt") then
2
    print("Expected lamps.txt. Create a file with space seperated names of each redstone integrator in the network. Each line represents one row in the theater.")
3
    return
4
end
5

6

7
local function set(p, enable)
8
    local sides = peripheral.call(p, "getSides")
9
    for i = 1, 6 do
10
        peripheral.call(p, "setOutput", sides[i], enable)
11
    end
12
end
13

14
local function animate(speed, enable)
15
    for line in io.lines("lamps.txt") do
16
        for p in line:gmatch("%S+") do
17
            set(p, enable)
18
        end
19
        sleep(speed)
20
    end
21
end
22

23
local speed, enable = ...
24
speed = tonumber(speed)
25
enable = enable == "true"
26
if speed and type(enable) == "boolean" then
27
    animate(speed, enable)
28
else
29
    printError("animate <speed:num> <enable:bool>")
30
end