Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Farside's Fuzzy Navigation API
- --get file stuff sorted declare variables
- map = {}
- newdirection = 0
- function getmapy()
- --reads for file and gets coords
- if fs.exists("mapy.sqrl") then
- memory = fs.open("mapy.sqrl", "r")
- --do stuff
- for i = 1, 5, 1 do
- local line = memory.readLine()
- if line then
- map[i] = line
- end
- end
- else
- memory = fs.open("mapy.sqrl", "a")
- memory.writeLine("0")
- memory.writeLine("0")
- memory.writeLine("0")
- memory.writeLine("1")
- memory.writeLine(tostring(turtle.getFuelLevel()))
- end
- memory.close()
- end
- --x = 0
- --y = 0
- --z = 0
- --compass = 1
- --new function write to file new position
- local function mapy()
- --write coords and heading to file
- memory = fs.open("mapy.sqrl", "w")
- for i = 1, 5, 1 do
- memory.writeLine(map[i])
- end
- memory.close()
- end
- local function locationy()
- getmapy()
- x = tonumber(map[1])
- y = tonumber(map[2])
- z = tonumber(map[3])
- compass = tonumber(map[4])
- print("locationy function")
- print("compass = ", map[4])
- if compass == 1 then
- x = x + 1
- map[1] = tostring(x)
- mapy()
- print("moving")
- end
- if compass == 2 then
- y = y + 1
- map [2] = tostring(y)
- mapy()
- end
- if compass == 3 then
- x = x - 1
- map[1] = tostring(x)
- mapy()
- end
- if compass == 4 then
- y = y - 1
- map[2] = tostring(y)
- mapy()
- end
- memory.close()
- end
- function forward()
- -- print(map[1], ", ", map[2])
- print("forward function")
- local fuel = tonumber(map[5])
- turtle.forward()
- local fuelb = turtle.getFuelLevel()
- -- print("fuel and fuelb ", fuel, ", ", fuelb)
- if fuel > fuelb then
- locationy()
- map[5] = tostring(turtle.getFuelLevel())
- mapy()
- -- print(x)
- -- print(y)
- -- print(z)
- -- print(compass)
- end
- end
- function heading()
- if newdirection == 1 then
- compass = 1
- map[4] = tostring(1)
- end
- if newdirection == 2 then
- compass = 2
- map[4] = tostring(2)
- end
- if newdirection == 3 then
- compass = 3
- map[4] = tostring(3)
- end
- if newdirection == 4 then
- compass = 4
- map[4] = tostring(4)
- end
- -- else
- -- print("I have lost my direction", newdirection)
- -- end
- mapy()
- end
- function turnRight()
- turtle.turnRight()
- if tonumber(map[4]) < 4 then
- newdirection = tonumber(map[4]) + 1
- print("here", newdirection)
- heading()
- elseif tonumber(map[4]) == 4 then
- newdirection = 1
- heading()
- end
- -- else
- -- print("turnright failed")
- end
- function turnLeft()
- turtle.turnLeft()
- if tonumber(map[4]) > 1 then
- newdirection = tonumber(map[4]) - 1
- heading()
- elseif tonumber(map[4]) == 1 then
- newdirection = 4
- heading()
- end
- end
- function up()
- local fuel = tonumber(map[5])
- turtle.up()
- local fuelb = turtle.getFuelLevel()
- if fuel > fuelb then
- map[3] = map[3] + 1
- map[5] = fuelb
- mapy()
- end
- end
- function down()
- local fuel = tonumber(map[5])
- turtle.down()
- local fuelb = turtle.getFuelLevel()
- if fuel > fuelb then
- map[3] = map[3] - 1
- map[5] = fuelb
- mapy()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement