-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.lua
76 lines (69 loc) · 1.36 KB
/
Console.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
key = "TurtleControlSystem"
rednet.open("back")
Main = nil
Ping = 0
ID = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
os.startTimer(1)
run = true
conectiontimer = 0
write("Conntecting.")
rednet.broadcast(key.."connectConsole")
while(run) do
event,param1,param2 = os.pullEvent()
--if(event ~= "timer") then
-- print(event)
-- print(param1)
-- print(param2)
--end
if(event == "char") then
if(param1 == "s") then
run = false
end
if(param1 == "h") then
os.shutdown()
end
end
if(event == "rednet_message") then
if(Main == nil and param2 == "connectMain") then
Main = param1
conectiontimer = nil
print("")
print("Connected")
end
if(Main ~= nil) then
if(param1 == Main) then
if(param2 == "pong") then
Ping = 0
end
end
end
end
if(Main ~= nil) then
if((Ping % 2) == 0) then
rednet.send(Main,"ping")
if(Ping > 6) then
conectiontimer = 0
Main = nil
print("Lost Connection to Main")
write("Conntecting.")
rednet.broadcast(key.."connectConsole")
end
end
Ping = Ping + 1
end
if(event == "timer") then
os.startTimer(1)
if(conectiontimer ~= nil) then
write(".")
conectiontimer = conectiontimer + 1
if(conectiontimer > 10) then
print("")
print("Timed Out")
run = false
end
if(run) then
rednet.broadcast(key.."connectConsole")
end
end
end
end