-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleporter v2.lua
94 lines (87 loc) · 2.18 KB
/
teleporter v2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
protocol = "teleporter1"; -- controls channel for tp pairs
modem = peripheral.find("modem", rednet.open)
mode = 0;
function sending()
repeat
local input = redstone.getInput("bottom")
os.sleep(0.05)
until (input);
print("\nInput Detected")
mode = 1;
end
function receiving()
repeat
local id, message = rednet.receive(protocol, 10)
until (message == protocol);
print("\nMessage Received")
mode = 2;
end
function returning()
local id, message = rednet.receive(protocol, 10)
print("\nReturn Requested")
mode = 3;
end
function sendDisk()
local loopCount = 0;
os.sleep(1)
turtle.select(1)
repeat
turtle.suckDown()
loopCount = loopCount + 1;
os.sleep(0.25)
until (turtle.getItemCount() > 0 or loopCount > 8);
if (loopCount > 8) then
print("\nSender was stuck in loop!")
end
turtle.drop()
rednet.broadcast(protocol, protocol)
print("\nDisk Sent")
end
function receiveDisk()
local loopCount = 0;
os.sleep(1)
turtle.select(1)
repeat
redstone.setOutput("bottom", true)
os.sleep(0.25)
redstone.setOutput("bottom", false)
os.sleep(0.25)
turtle.suckDown()
loopCount = loopCount + 1;
until (turtle.getItemCount() > 0 or loopCount > 8);
if (loopCount > 8) then
print("\nReceiver was stuck in loop!")
end
turtle.dropDown()
print("\nDisk Received")
os.sleep(4)
end
function returnDisk()
local loopCount = 0;
turtle.select(1)
repeat
redstone.setOutput("bottom", true)
os.sleep(0.25)
redstone.setOutput("bottom", false)
os.sleep(0.25)
turtle.suckDown()
loopCount = loopCount + 1;
until (turtle.getItemCount() > 0 or loopCount > 8);
if (loopCount > 8) then
print("\nReturner was stuck in loop!")
end
turtle.drop()
print("\nDisk Returned")
os.sleep(1)
end
repeat
parallel.waitForAny(sending, receiving)
if (mode == 1) then
sendDisk()
elseif (mode == 2) then
parallel.waitForAny(receiveDisk, returning)
if (mode == 3) then
returnDisk()
end
end
until (false);