SHOW:
|
|
- or go back to the newest paste.
| 1 | -- ############################## | |
| 2 | - | -- msg_sender test3a |
| 2 | + | -- msg_sender test4 |
| 3 | -- http://hevohevo.hatenablog.com/ | |
| 4 | ||
| 5 | rednet.open("right")
| |
| 6 | ||
| 7 | local args = {...}
| |
| 8 | assert(args and #args>0, "msg_sender <receiver_id>") | |
| 9 | local receiver_id = tonumber(args[1]) | |
| 10 | ||
| 11 | local trans_tbl = {
| |
| 12 | w="turtle.forward()", | |
| 13 | a="turtle.turnLeft() turtle.forward() turtle.turnRight()", | |
| 14 | s="turtle.back()", | |
| 15 | d="turtle.turnRight() turtle.forward() turtle.turnLeft()", | |
| 16 | space="turtle.up()", | |
| 17 | leftShift="turtle.down()", | |
| 18 | - | right="turtle.turnRight()", |
| 18 | + | left="turtle.turnRight()", |
| 19 | - | left="turtle.turnLeft()", |
| 19 | + | right="turtle.turnLeft()", |
| 20 | - | z="os.run({},'boring')", -- run other program
|
| 20 | + | z="shell.run('dance')", -- let's dance!
|
| 21 | - | x="os.run({},'rom/programs/turtle/dance')" -- let's dance!
|
| 21 | + | x="shell.run('boring')", -- run receiver's other program
|
| 22 | c="hevo()" -- call receiver's function | |
| 23 | } | |
| 24 | ||
| 25 | print("Press 'q' to terminate")
| |
| 26 | while true do | |
| 27 | local event, scancode = os.pullEvent("key")
| |
| 28 | local keyname = keys.getName(scancode) | |
| 29 | local message = trans_tbl[keyname] | |
| 30 | if keyname == "q" then break end | |
| 31 | print(keyname," => ",message or "none") | |
| 32 | ||
| 33 | if message then | |
| 34 | rednet.send(receiver_id, message) | |
| 35 | - | end |
| 35 | + | |
| 36 | end | |
| 37 | print("Terminated") |