SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Awake | |
| 2 | print("Mining server awake: Hello World!")
| |
| 3 | ||
| 4 | -- Setup wireless | |
| 5 | - | local modemSide = "right" |
| 5 | + | local modemSide = "left" |
| 6 | local modem = peripheral.wrap(modemSide) | |
| 7 | -- 5 Server -> Client | |
| 8 | -- 6 Client -> Server | |
| 9 | -- 7 Server -> Pocket Computer | |
| 10 | modem.open(5) | |
| 11 | - | print("Channel 5 and 6 are open")
|
| 11 | + | |
| 12 | modem.open(7) | |
| 13 | modem.open(8) | |
| 14 | print("Channel 5 and 6 are open, as well as 7 and 8")
| |
| 15 | ||
| 16 | -- Setup sending wireless messages | |
| 17 | - | event, |
| 17 | + | |
| 18 | - | eventModemSide, |
| 18 | + | |
| 19 | - | senderChannel, |
| 19 | + | |
| 20 | - | replyChannel, |
| 20 | + | function SendMessageToPocketComputer(message) |
| 21 | - | message, |
| 21 | + | modem.transmit(7, 7, message) |
| 22 | - | senderDistance = |
| 22 | + | |
| 23 | - | os.pullEvent( |
| 23 | + | |
| 24 | - | "modem_message" |
| 24 | + | --Pocket computer helper |
| 25 | - | ) |
| 25 | + | function printf(m) |
| 26 | - | print("Message received: " + message)
|
| 26 | + | print(m) |
| 27 | - | if(message == messageCompare) then |
| 27 | + | SendMessageToPocketComputer(m) |
| 28 | end | |
| 29 | printf("Link to pocket computer established. Hello")
| |
| 30 | ||
| 31 | -- Setup receiving wireless messages | |
| 32 | function WaitForMessage(messageCompare) | |
| 33 | while true do | |
| 34 | local | |
| 35 | a,b,c,d,e,f = os.pullEvent("modem_message")
| |
| 36 | printf("Message received: " .. tostring(e))
| |
| 37 | if(e == messageCompare) then | |
| 38 | break | |
| 39 | - | print("How many turtles are mining? >>")
|
| 39 | + | |
| 40 | - | local desiredTurtleCount = read() |
| 40 | + | |
| 41 | end | |
| 42 | ||
| 43 | - | print("How many cycles should they mine for? >>")
|
| 43 | + | |
| 44 | - | local desiredCycleCount = read() |
| 44 | + | printf("How many turtles are mining? >>")
|
| 45 | local desiredTurtleCount = tonumber(read()) | |
| 46 | ||
| 47 | - | print("Sending awake signal to all turtles...")
|
| 47 | + | |
| 48 | - | print(5) |
| 48 | + | printf("How many cycles should they mine for? >>")
|
| 49 | - | os.sleep(1) |
| 49 | + | local desiredCycleCount = tonumber(read()) |
| 50 | - | print(4) |
| 50 | + | |
| 51 | - | os.sleep(1) |
| 51 | + | |
| 52 | - | print(3) |
| 52 | + | printf("Sending awake signal to all turtles...")
|
| 53 | - | os.sleep(1) |
| 53 | + | |
| 54 | - | print(2) |
| 54 | + | |
| 55 | - | os.sleep(1) |
| 55 | + | |
| 56 | - | print(1) |
| 56 | + | |
| 57 | - | os.sleep(1) |
| 57 | + | printf("Waiting for turtles to register...")
|
| 58 | local turtleCount = 0 | |
| 59 | while true do | |
| 60 | WaitForMessage("_TurtleRegistered")
| |
| 61 | turtleCount = turtleCount + 1 | |
| 62 | - | print("Waiting for turtles to register...")
|
| 62 | + | printf("Turtle registered. Count is " .. tostring(turtleCount))
|
| 63 | if(turtleCount == desiredTurtleCount) then break end | |
| 64 | end | |
| 65 | ||
| 66 | -- Begin when user is ready | |
| 67 | - | print("Turtle registered. Count is " + turtleCount)
|
| 67 | + | printf("Press any key when ready to begin >>")
|
| 68 | read() | |
| 69 | SendMessage("_Begin")
| |
| 70 | ||
| 71 | -- Begin managing mine operations | |
| 72 | - | print("Press any key when ready to begin >>")
|
| 72 | + | printf("Mining...")
|
| 73 | local readyCount = 0 | |
| 74 | local cycleCount = 1 | |
| 75 | while true do | |
| 76 | - | print("Mining...")
|
| 76 | + | printf("Starting mine cycle #" .. tostring(cycleCount))
|
| 77 | modem.transmit(8, 8, "Starting mine cycle #" .. tostring(cycleCount)) | |
| 78 | SendMessage("_StartNextCycle")
| |
| 79 | printf("Waiting for turtles to be ready for next cycle...")
| |
| 80 | - | print("Starting mine cycle #" + cycleCount)
|
| 80 | + | |
| 81 | while true do | |
| 82 | - | print("Waiting for turtles to be ready for next cycle...")
|
| 82 | + | |
| 83 | readyCount = readyCount + 1 | |
| 84 | printf("A turtle is ready. Ready count is " .. tostring(readyCount))
| |
| 85 | if(readyCount == turtleCount) then | |
| 86 | printf("All turtles ready")
| |
| 87 | - | print("A turtle is ready. Ready count is " + readyCount)
|
| 87 | + | |
| 88 | end | |
| 89 | - | print("All turtles ready")
|
| 89 | + | |
| 90 | if(cycleCount == desiredCycleCount) then | |
| 91 | printf("All cycle complete")
| |
| 92 | break | |
| 93 | - | cycleCount = cycleCount + 1 |
| 93 | + | |
| 94 | cycleCount = cycleCount + 1 | |
| 95 | - | print("All cycle complete")
|
| 95 | + | printf(">>")
|
| 96 | printf(">>")
| |
| 97 | printf(">>")
| |
| 98 | - | print("")
|
| 98 | + | |
| 99 | ||
| 100 | -- Done | |
| 101 | printf("Goodbye >>")
| |
| 102 | - | print("Goodbye >>")
|
| 102 | + |