SHOW:
|
|
- or go back to the newest paste.
1 | function ping() | |
2 | rednet.open("back") | |
3 | rednet.broadcast("PINGchat","kdchat") | |
4 | end | |
5 | ||
6 | function pong() | |
7 | rednet.open("back") | |
8 | senderId, message, protocol = rednet.receive() | |
9 | if message == "PINGchat" then | |
10 | rednet.send(senderId,"PONGchat",protocol) | |
11 | setupChat() | |
12 | else | |
13 | pong() | |
14 | end | |
15 | end | |
16 | function setupChat() | |
17 | if term.isColor() then | |
18 | term.setBackgroundColor(colors.white) | |
19 | term.setTextColor(colors.black) | |
20 | return "color" | |
21 | else | |
22 | return "no color" | |
23 | end | |
24 | end | |
25 | function writingChat() | |
26 | while true do | |
27 | msg = io.read() | |
28 | if msg == "/exit" then | |
29 | error("User exited program!") | |
30 | else | |
31 | print(user..": "..msg) | |
32 | rednet.send(senderId,msg,protocol) | |
33 | end | |
34 | end | |
35 | end | |
36 | function receivingChat() | |
37 | while true do | |
38 | rednet.receive(protocol) | |
39 | end | |
40 | end | |
41 | function coroutineController() | |
42 | chatIn = coroutine.create(receivingChat()) | |
43 | coroutine.resume(chatIn) | |
44 | end | |
45 | ping() | |
46 | pong() | |
47 | ping() | |
48 | coroutineController() | |
49 | writingChat() |