-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevator_client.lua
50 lines (45 loc) · 1.07 KB
/
elevator_client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
rednet.open("back")
delay = .5
cable = "bottom"
elevatorID = 43
serverID = 35
function moveUp()
redstone.setBundledOutput(cable, colors.orange)
sleep(delay)
redstone.setBundledOutput(cable, 0)
sleep(delay)
end
function moveDown()
redstone.setBundledOutput(cable, colors.white)
sleep(delay)
redstone.setBundledOutput(cable, 0)
sleep(delay)
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Waiting for input")
local senderId, desiredLevel, protocol = rednet.receive("elevator")
rednet.send(elevatorID, "getGPS", "elevator_gps")
print("Waiting for gps response:")
local elevatorID, currentLevel = rednet.receive("elevator_gps",5)
print("currently on level:")
print(currentLevel)
sleep(3)
levels = currentLevel - desiredLevel
if levels > 0 then
print("moving down!")
for i = 1,levels do
moveDown()
end
elseif levels < 0 then
levels = math.abs(levels)
print("moving up!")
for i = 1,levels do
moveUp()
end
elseif levels == 0 then
print("Already on that level!")
sleep(3)
end
end