SHOW:
|
|
- or go back to the newest paste.
| 1 | - | rednet.open("left")
|
| 1 | + | --THINGS TO ADD: Fuel Meter, fix checkState(), auto startup |
| 2 | ||
| 3 | local isRunning = true | |
| 4 | local minFuel = 10 | |
| 5 | ||
| 6 | function Quit() | |
| 7 | isRunning = false | |
| 8 | term.setCursorPos(1,1) | |
| 9 | term.setBackgroundColour(colours.black) | |
| 10 | term.setTextColour(colours.white) | |
| 11 | term.clear() | |
| 12 | error() | |
| 13 | end | |
| 14 | ||
| 15 | local function checkFuel() | |
| 16 | if turtle.getFuelLevel() < minFuel then | |
| 17 | print("Refueling!")
| |
| 18 | turtle.select(16) | |
| 19 | while turtle.getFuelLevel() < minFuel do | |
| 20 | turtle.refuel(1) | |
| 21 | - | |
| 21 | + | os.sleep(0.1) |
| 22 | - | turtle.refuel() |
| 22 | + | end |
| 23 | else | |
| 24 | print("Fuel sufficient!")
| |
| 25 | return | |
| 26 | end | |
| 27 | end | |
| 28 | ||
| 29 | local function getModem() | |
| 30 | for a,b in pairs(rs.getSides()) do | |
| 31 | if peripheral.getType(b) == "modem" and peripheral.call(b,"isWireless") then | |
| 32 | return b | |
| 33 | end | |
| 34 | end | |
| 35 | end | |
| 36 | ||
| 37 | function checkState() | |
| 38 | if not rednet.isOpen() then | |
| 39 | print("Opening socket!")
| |
| 40 | side = getModem() | |
| 41 | rednet.open(side) | |
| 42 | if rednet.isOpen() then | |
| 43 | print("Connected!")
| |
| 44 | return | |
| 45 | else | |
| 46 | print("Error, reconnecting!")
| |
| 47 | rednet.open(side) | |
| 48 | end | |
| 49 | end | |
| 50 | end | |
| 51 | ||
| 52 | while true do | |
| 53 | isRunning = true | |
| 54 | checkState() | |
| 55 | id,message = rednet.receive() | |
| 56 | if message == "forward" then | |
| 57 | turtle.forward() | |
| 58 | elseif message == "backwards" then | |
| 59 | turtle.back() | |
| 60 | elseif message == "left" then | |
| 61 | turtle.turnLeft() | |
| 62 | turtle.forward() | |
| 63 | turtle.turnRight() | |
| 64 | elseif message == "right" then | |
| 65 | turtle.turnRight() | |
| 66 | turtle.forward() | |
| 67 | turtle.turnLeft() | |
| 68 | elseif message == "turnleft" then | |
| 69 | turtle.turnLeft() | |
| 70 | elseif message == "turnright" then | |
| 71 | turtle.turnRight() | |
| 72 | elseif message == "action" then | |
| 73 | turtle.dig() | |
| 74 | elseif message == "quit" then | |
| 75 | Quit() | |
| 76 | end | |
| 77 | checkFuel() | |
| 78 | end |