SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Awake | |
| 2 | print("Mining client awake: Hello World!")
| |
| 3 | ||
| 4 | -- Setup wireless | |
| 5 | local modem = peripheral.wrap("right")
| |
| 6 | - | -- 11 Server -> Client |
| 6 | + | -- 5 Server -> Client |
| 7 | - | -- 12 Client -> Server |
| 7 | + | -- 6 Client -> Server |
| 8 | modem.open(11) | |
| 9 | modem.open(12) | |
| 10 | print("Channel 11 and 12 are open")
| |
| 11 | ||
| 12 | function IsTurtle() | |
| 13 | local success, data = turtle.inspect() | |
| 14 | if success then | |
| 15 | return data.name == "computercraft:turtle_advanced" | |
| 16 | else | |
| 17 | return false | |
| 18 | end | |
| 19 | end | |
| 20 | ||
| 21 | -- Setup receiving wireless messages | |
| 22 | function WaitForMessage(messageCompare) | |
| 23 | while true do | |
| 24 | local a,b,c,d,e,f = os.pullEvent("modem_message")
| |
| 25 | print("Message received: ")
| |
| 26 | print(e) | |
| 27 | if(e == messageCompare) then | |
| 28 | print("Message accepted")
| |
| 29 | break | |
| 30 | end | |
| 31 | end | |
| 32 | end | |
| 33 | ||
| 34 | -- Setup sending wireless messages | |
| 35 | function SendMessage(message) | |
| 36 | modem.transmit(12, 11, message) | |
| 37 | end | |
| 38 | ||
| 39 | -- Forward shorthand | |
| 40 | function Forward() | |
| 41 | while not turtle.forward() do | |
| 42 | if (turtle.detect() and not IsTurtle()) then turtle.dig() end | |
| 43 | turtle.attack() | |
| 44 | - | while not IsTurtle() do |
| 44 | + | |
| 45 | - | turtle.forward() |
| 45 | + | |
| 46 | ||
| 47 | -- Main loop | |
| 48 | while true do | |
| 49 | print("Waiting to start next cycle")
| |
| 50 | WaitForMessage("_StartNextCycle")
| |
| 51 | print("Starting next cycle...")
| |
| 52 | Forward() | |
| 53 | Forward() | |
| 54 | Forward() | |
| 55 | Forward() | |
| 56 | print(">>")
| |
| 57 | print(">>")
| |
| 58 | print(">>")
| |
| 59 | end | |
| 60 | ||
| 61 | print("Goodbye >>")
| |
| 62 | read() |