SHOW:
|
|
- or go back to the newest paste.
| 1 | ----------------------------------------------------------------------------- | |
| 2 | -- Name: RCreceive | |
| 3 | - | -- Version: 1.1.3 |
| 3 | + | -- Version: 1.1.4 |
| 4 | -- Author: Dustin Rosebery | |
| 5 | -- Setup: install on a wireless mining turtle. Requires latest version of | |
| 6 | -- RCmaster installed on a computer with a 4x4 advanced monitor | |
| 7 | -- Description: Receiver program that controls turtle movement and sends | |
| 8 | -- inventory information to the master program | |
| 9 | ----------------------------------------------------------------------------- | |
| 10 | ||
| 11 | rednet.open("left")
| |
| 12 | t = turtle | |
| 13 | ||
| 14 | -- checks for empty inventory and returns name and amount of item in slot i | |
| 15 | function checkInventory(i) | |
| 16 | t.select(i) | |
| 17 | amount = t.getItemCount() | |
| 18 | data = t.getItemDetail() | |
| 19 | ||
| 20 | sleepTime = 0 | |
| 21 | os.sleep(sleepTime) | |
| 22 | if amount == 0 then | |
| 23 | rednet.broadcast("empty")
| |
| 24 | else | |
| 25 | rednet.broadcast(data.name) | |
| 26 | rednet.broadcast(data.count) | |
| 27 | end | |
| 28 | listen() | |
| 29 | end | |
| 30 | ||
| 31 | -- listens for broadcasts from master | |
| 32 | function listen() | |
| 33 | senderID, message, protocol = rednet.receive() | |
| 34 | write("Received: " .. message .. "\n")
| |
| 35 | ||
| 36 | if message == "forward" then | |
| 37 | t.forward() | |
| 38 | elseif message == "back" then | |
| 39 | t.back() | |
| 40 | elseif message == "left" then | |
| 41 | t.turnLeft() | |
| 42 | elseif message == "right" then | |
| 43 | t.turnRight() | |
| 44 | elseif message == "up" then | |
| 45 | t.up() | |
| 46 | elseif message == "down" then | |
| 47 | t.down() | |
| 48 | elseif message == "place" then | |
| 49 | t.place() | |
| 50 | sID, i, proto = rednet.receive() | |
| 51 | checkInventory(i) | |
| 52 | elseif message == "dig" then | |
| 53 | t.dig() | |
| 54 | elseif message >= 1 and message <= 16 then | |
| 55 | checkInventory(message) | |
| 56 | else | |
| 57 | listen() | |
| 58 | end | |
| 59 | end | |
| 60 | ||
| 61 | while(true) do | |
| 62 | listen() | |
| 63 | end |