Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get jB8bm6Hw startup
- -- -------------------------------------------
- -- 3D Printer Scaner -Sinkir-
- -- Version 0.2 (2014/10/21)
- -- SCANER FUNCTION :
- -- slot 16 ender chest Fuel +-+-+-+-+
- -- slot 15 ender chest dump Resources | | | | |
- -- slot 8 to 14 resources to Compare | | | |c|
- -- slot 1 to 7 slots for mining |c|c|c|c|
- -- |c|c|R|F|
- -- +-+-+-+-+
- -- -------------------------------------------
- -- 3D PRINTER FUNCTION :
- -- slot 16 ender chest Fuel +-+-+-+-+
- -- slot 15 ender chest dump Resources | | | | |
- -- slot 8 to 14 ender Chest of resources | | | |c|
- -- slot 1 to 7 slots for store resources |c|c|c|c|
- -- |c|c|R|F|
- -- +-+-+-+-+
- -- -------------------------------------------
- -- --------------------
- -- format : x,y,z,facing
- -- (n e s w)
- --
- --
- -- `.+x |-z +y.'
- -- `. | .'
- -- `. |up .'
- -- north`. | .' east
- -- `. | .'
- -- :+:
- -- .' | `.
- -- west.' | `. south
- -- .' | `.
- -- .' |down `.
- -- .'-y +z| -x`.
- --
- -- yes +z is for down
- -- --------------------
- -- Exemple of data file:
- -- --------------------
- -- SizeX,SizeY,SizeZ,ProjectName,Function,posX,posY,posZ,Facing
- -- ex:
- -- "7,3,3,UglyCone,scan,4,2,0,s"
- --
- -- --------------------
- -- Exemple of data of project file:
- -- --------------------
- --
- -- ex: for 7x3x3 (x,y,z)
- -- 1=stone 2=glass
- --
- -- " "
- -- " 1 "
- -- " "
- --
- -- " 2 "
- -- " 1 "
- -- " 2 "
- --
- -- " 2 "
- -- " 212 "
- -- " 2 "
- dataFilePath = "mydata"
- urlPhp = "http://sinkir.free.fr/turtle3d/"
- -- _____
- -- | ___| _ _ __ ___
- -- | |_ | | | | '_ \ / __|
- -- | _|| |_| | | | | (__
- -- |_| \__,_|_| |_|\___|
- --
- function checkLabel()
- if(os.getComputerLabel() == nil)then
- os.setComputerLabel(httpget("turtlegetlabel"))
- end
- end
- function checkStop()
- if(os.getComputerLabel() == nil)then
- if(httpget("turtlegetstop") == "1")then
- sleep(30)
- os.reboot()
- end
- else
- if(httpget("turtlegetstop&label="..os.getComputerLabel()) == "1")then
- sleep(30)
- os.reboot()
- end
- end
- end
- function httpget(param)
- local sExample = http.get(urlPhp.."?a="..param) --Get contents of page
- --sleep(2)
- --print(param)
- if(sExample == nil)then
- print("sE nil sleep and retry")
- sleep(2)
- return httpget(param)
- end
- local txt = sExample.readAll()
- sExample.close()
- --Just in case
- sleep(0.2)
- --print(txt)
- return txt
- end
- function testFuel()
- if(fuel() < 10)then
- if(count(16) == 0)then
- print("slot 16 empty")
- sleep(20)
- os.reboot()
- end
- print('Plus de coco, test de refuel')
- while(turtle.detectUp())do
- turtle.digUp()
- sleep(1)
- end
- select(16)
- turtle.placeUp()
- sleep(1)
- --print('Placed, sucking..')
- if(turtle.suckUp() == false)then
- turtle.digUp()
- print("Suck fuel false")
- sleep(20)
- os.reboot()
- end
- turtle.refuel()
- turtle.digUp()
- end
- return true
- end
- function go()
- select(1)
- if(turtle.detect()==true)then
- if(turtle.dig()==false)then
- return false
- else
- sleep(1)
- if(turtle.detect()==true)then
- while(i<50)do
- i=i+1
- if(turtle.dig()==true)then
- sleep(1)
- if(turtle.forward()==true)then
- return true
- else
- return false
- end
- end
- sleep(0.2)
- end
- else
- if(turtle.forward()==true)then
- return true
- else
- return false
- end
- end
- end
- else
- if(turtle.forward()==true)then
- return true
- else
- while(i<50)do
- i=i+1
- turtle.attack()
- sleep(0.2)
- end
- if(turtle.forward()==true)then
- return true
- else
- return false
- end
- end
- end
- return false
- end
- function down()
- select(1)
- if(turtle.detectDown()==true)then
- if(turtle.digDown()==false)then
- return false
- else
- sleep(1)
- if(turtle.detectDown()==true)then
- while(i<50)do
- i=i+1
- if(turtle.digDown()==true)then
- sleep(1)
- if(turtle.down()==true)then
- return true
- else
- return false
- end
- end
- sleep(0.2)
- end
- else
- if(turtle.down()==true)then
- return true
- else
- return false
- end
- end
- end
- else
- if(turtle.down()==true)then
- return true
- else
- while(i<50)do
- i=i+1
- turtle.attackDown()
- sleep(0.2)
- end
- return false
- end
- end
- return false
- end
- function up()
- select(1)
- if(turtle.detectUp()==true)then
- if(turtle.digUp()==false)then
- return false
- else
- sleep(1)
- if(turtle.detectUp()==true)then
- while(i<50)do
- i=i+1
- if(turtle.digUp()==true)then
- sleep(1)
- if(turtle.up()==true)then
- return true
- else
- return false
- end
- end
- sleep(0.2)
- end
- else
- if(turtle.up()==true)then
- return true
- else
- return false
- end
- end
- end
- else
- if(turtle.up()==true)then
- return true
- else
- while(i<50)do
- i=i+1
- turtle.attackUp()
- sleep(0.2)
- end
- return false
- end
- end
- return false
- end
- function downScaner()
- checkInvScaner()
- local flag = false
- local i = 0
- if(turtle.detectDown()==true)then
- for i=8,14 do
- if(count(i)>0)then
- select(i)
- if(turtle.compareDown()==true)then
- addChar(i-7)
- flag = true
- i =15
- end
- end
- end
- if(flag == false)then
- print("Unknow block")
- addChar("0")
- end
- select(1)
- turtle.digDown()
- else
- addChar("0")
- end
- return true
- end
- function addChar(c)
- c = tostring(c)
- local tmp = ""
- if(fs.exists(dataProjectFilePath))then
- tmp = fileGet(dataProjectFilePath)
- fileSet(dataProjectFilePath, tmp..c)
- else
- fileSet(dataProjectFilePath, c)
- end
- end
- function addNames(slot, name)
- slot = tostring(slot - 7)
- if(fs.exists(dataProjectFilePath.."names"))then
- tmp = fileGet(dataProjectFilePath.."names")
- fileSet(dataProjectFilePath.."names", tmp..slot..","..name.."-")
- else
- fileSet(dataProjectFilePath.."names", slot..","..name.."-")
- end
- end
- function suck(dir)
- local flag = false
- if(dir == "go")then
- flag = turtle.suck(64)
- elseif(dir == "up")then
- flag = turtle.suckUp(64)
- elseif(dir == "down")then
- flag = turtle.suckDown(64)
- end
- if(flag == false)then
- return false
- end
- return true
- end
- --
- --
- left = function()
- if(turtle.turnLeft()==false)then
- sleep(1)
- left()
- else
- return true
- end
- end
- right = function()
- if(turtle.turnRight()==false)then
- sleep(1)
- right()
- else
- return true
- end
- end
- count = function(id)
- return turtle.getItemCount(id)
- end
- back = function()
- return turtle.back()
- end
- select = function(id)
- return turtle.select(id)
- end
- fuel = function()
- return turtle.getFuelLevel()
- end
- move = function(id, nb)
- return turtle.transferTo(id, nb)
- end
- --
- --
- function fileGet(path)
- local tabFile
- if(fs.exists(path))then
- tabFile = fs.open(path, "r")
- if tabFile then
- text = tabFile.readAll()
- tabFile.close()
- end
- return text
- else
- print("fileGet() File not found.")
- print(path)
- return false
- end
- end
- function fileSet(path, text)
- local tabFile
- if(fs.isReadOnly(path))then
- print("fileSet() File is read only.")
- print(path)
- return false
- else
- tabFile = fs.open(path, "w")
- if tabFile then
- tabFile.write(text)
- tabFile.close()
- end
- return true
- end
- end
- function split(str, pat)
- -- source of the function :
- -- http://lua-users.org/wiki/SplitJoin
- -- Compatibility: Lua-5.1
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function printTab(tab)
- for key, value in pairs(tab) do
- print("[".. key .."]"..value.."")
- end
- end
- --
- --
- function checkSlotVideScaner()
- if(count(6) == 0 and count(7) == 0)then
- return true
- end
- return false
- end
- function checkInvScaner()
- -- check si il reste un slot de vide
- if(checkSlotVideScaner() == false) then
- if(videInvScaner()==false)then
- return false
- end
- end
- return true
- end
- function videInvScaner()
- local i = 0
- while(turtle.detectUp())do
- turtle.digUp()
- sleep(1)
- end
- select(15)
- if(turtle.placeUp() == false)then
- print("turtle.placeUp false")
- sleep(20)
- os.reboot()
- end
- sleep(0.2)
- for i=1,7 do
- if(count(i)>0)then
- select(i)
- turtle.dropUp(count(i))
- end
- end
- select(15)
- turtle.digUp()
- return true
- end
- function initScan()
- local input = ""
- if(count(16) == 0)then
- print("No ender chest for fuel in slot 16.., exit")
- return false
- end
- if(count(15) == 0)then
- print("No ender chest for dump resources in slot 15, exit")
- return false
- end
- print("plz only 'A to z' no space")
- for i=8,14 do
- if(count(i)>0)then
- select(i)
- print("Add a name for the slot "..i.."")
- input = read()
- addNames(i, input)
- end
- end
- shaundy("newproject")
- return true
- end
- function getNames()
- local tab = split(fileGet(dataProjectFilePath.."names"), "-")
- return tab
- end
- function initPrint()
- local r = {}
- local t = {}
- local slotId = ""
- local slotName = ""
- if(count(16) == 0)then
- print("No ender chest for fuel in slot 16.., exit")
- return false
- end
- if(count(15) == 0)then
- print("No ender chest for dump resources in slot 15, exit")
- return false
- end
- print("getting data from project "..projectName)
- if(shaundy("getproject") == false)then
- return false
- end
- getGlobals()
- --posZ = sizeZ-1
- setGlobals()
- if(shaundy("getdata") == false)then
- return false
- end
- r = getNames()
- for k,v in pairs(r) do
- t = split((v), ",")
- print("EndChest slot"..(tonumber(t[1]) + 7).." of "..t[2])
- end
- print("Write 'ok' when ready")
- input = read()
- if(input == "ok")then
- return true
- else
- shell.exit()
- end
- return true
- end
- function init()
- local input = ""
- print("Hi ! 3D printer and scaner on duty\n")
- print("scan or print ?")
- input = read()
- if(input == "print")then
- scanOrPrint = "print"
- else
- scanOrPrint = "scan"
- print("X size ?")
- input = read()
- sizeX = tonumber(input)
- print("Y size ?")
- input = read()
- sizeY = tonumber(input)
- print("Z size ?")
- input = read()
- sizeZ = tonumber(input)
- end
- print("Project name ? (no special char plz)")
- input = read()
- projectName = tostring(input)
- dataProjectFilePath = "p"..projectName
- if(scanOrPrint == "print")then
- -- 3D PRINTER FUNCTION :
- print("s16 endchest Fuel +-+-+-+-+")
- print("s15 endchest dump Resou | | | | |")
- print("s8-14 ender Chest resou | | | |c|")
- print("s1-7 store resources |c|c|c|c|")
- print(" |c|c|R|F|")
- print(" +-+-+-+-+")
- else
- -- 3D SCANER FUNCTION :
- print("Set up inventory like this :")
- print("s16 endchest Fuel +-+-+-+-+")
- print("s15 endchest dump Resou | | | | |")
- print("s8-14 resources Compare | | | |c|")
- print("s1-7 slots for mining |c|c|c|c|")
- print(" |c|c|R|F|")
- print(" +-+-+-+-+")
- print("Write 'ok' when ready")
- input = read()
- if(input == "ok")then
- print("saving data in "..dataFilePath)
- fileSet(dataFilePath, tostring(sizeX)..","..tostring(sizeY)..","..tostring(sizeZ)..","..projectName..","..scanOrPrint..",0,0,0,n")
- else
- shell.exit()
- end
- end
- end
- function getGlobals()
- local r = {}
- local tab = split(fileGet(dataFilePath), ",")
- sizeX = tonumber(tab[1])
- sizeY = tonumber(tab[2])
- sizeZ = tonumber(tab[3])
- projectName = tab[4]
- scanOrPrint = tab[5]
- posX = tonumber(tab[6])
- posY = tonumber(tab[7])
- posZ = tonumber(tab[8])
- facing = tab[9]
- end
- function getmygoto()
- if(fs.exists("mygoto") == false)then
- return false
- end
- local tx = fileGet("mygoto")
- if(tx == "")then
- fs.delete("mygoto")
- sleep(0.2)
- if(fs.exists("mygoto"))then
- print("Fukin fs.delete de merde")
- print("Write 'fuck' plz")
- input = read()
- if(input == "fuck")then
- print("ty :'(")
- sleep(2)
- shell.exit()
- else
- sleep(20)
- shell.exit()
- end
- end
- return false
- end
- local tab = split(tx , ",")
- fakeX = tonumber(tab[1])
- fakeY = tonumber(tab[2])
- fakeZ = tonumber(tab[3])
- fakeFacing = tab[4]
- fakeC = tab[5]
- end
- function setGlobals()
- --print("setGlobals")
- fileSet(dataFilePath, tostring(sizeX)..","..tostring(sizeY)..","..tostring(sizeZ)..","..projectName..","..scanOrPrint..","..tostring(posX)..","..tostring(posY)..","..tostring(posZ)..","..facing)
- end
- function isPair(n)
- if(n == 0)then
- return true
- end
- if(n % 2 == 0)then
- return true
- else
- return false
- end
- end
- function finis()
- if(scanOrPrint == "scan")then
- shaundy("sendLine")
- shaundy("sendEnd")
- end
- sleep(0.2)
- fileSet(dataFilePath, "")
- sleep(0.2)
- fs.delete(dataFilePath)
- sleep(0.2)
- fileSet(dataProjectFilePath, "")
- sleep(0.2)
- fs.delete(dataProjectFilePath)
- sleep(0.2)
- fileSet(dataProjectFilePath.."names", "")
- sleep(0.2)
- fs.delete(dataProjectFilePath.."names")
- sleep(0.2)
- fs.delete("mygoto")
- sleep(0.2)
- fs.delete("names")
- sleep(0.2)
- fs.delete(dataFilePath)
- fs.delete(dataFilePath)
- fs.delete(dataFilePath)
- fs.delete(dataFilePath)
- print("Over exit")
- shell.exit()
- end
- function shaundy(order)
- print("shaundy "..order)
- --sleep(2)
- local input = ""
- if(order == "newproject")then
- if(httpget("turtle&do=newproject&projectname="..projectName.."&sizeX="..sizeX.."&sizeY="..sizeY.."&sizeZ="..sizeZ.."&names="..fileGet(dataProjectFilePath.."names")) == "ok")then
- return true
- else
- print("http newproject false sleep(30)")
- sleep(30)
- return shaundy("newproject")
- end
- end
- if(order == "sendLine")then
- if(scanOrPrint == "scan")then
- if(httpget("turtle&do=line&projectname="..projectName.."&posY="..posY.."&data="..fileGet(dataProjectFilePath)) == "ok")then
- --print("fileSet shaundy(sendLine)")
- fileSet(dataProjectFilePath, "")
- return true
- else
- print("http sendLine false sleep(30)")
- sleep(30)
- return shaundy("sendLine")
- end
- end
- end
- if(order == "sendNewLine")then
- if(scanOrPrint == "scan")then
- if(httpget("turtle&do=newline&projectname="..projectName.."&posZ="..posZ) == "ok")then
- return true
- else
- print("http sendNewLine false sleep(30)")
- sleep(30)
- return shaundy("sendNewLine")
- end
- else
- return shaundy("getdata")
- end
- end
- if(order == "sendEnd")then
- if(httpget("turtle&do=end&projectname="..projectName) == "ok")then
- return true
- else
- print("http sendEnd false sleep(30)")
- sleep(30)
- return shaundy("sendEnd")
- end
- end
- if(order == "getproject")then
- input = httpget("turtle&do=getproject&projectname="..projectName)
- --print("fileSet shaundy(getproject)")
- fileSet(dataFilePath, input)
- input = httpget("turtle&do=getprojectnames&projectname="..projectName)
- --print("fileSet shaundy(getprojectnames)")
- fileSet(dataProjectFilePath.."names", input)
- end
- if(order == "getdata")then
- --getGlobals()
- if(fakeZ >= sizeZ-1) then
- finis()
- end
- input = httpget("turtle&do=getdata&projectname="..projectName.."&z="..((sizeZ-1) - fakeZ))
- --input = httpget("turtle&do=getdata&projectname="..projectName.."&z="..(fakeZ))
- --print("getdata : "..input)
- fileSet(dataProjectFilePath, input)
- end
- end
- function testInvPrint()
- local i=0
- local counter = 0
- for i=1, 14 do
- if(count(i) == 0)then
- counter = counter + 1
- end
- end
- if(counter < 2)then
- --videInvPrint
- while(turtle.detectUp())do
- turtle.digUp()
- sleep(1)
- end
- select(15)
- turtle.placeUp()
- sleep(1)
- for i=8, 14 do
- if(count(i) > 1)then
- select(i)
- turtle.dropUp()
- end
- end
- select(15)
- sleep(1)
- turtle.digUp()
- end
- end
- function printTest()
- local c = ""
- local i = 0
- testInvPrint()
- if(turtle.detectDown()==true)then
- turtle.digDown()
- end
- c = tonumber(fakeC)
- if(c ~= nil and c > 0 and c < 8)then
- if(count(c) < 2)then
- select(c+7)
- if(turtle.compareTo(c)==true)then
- turtle.transferTo(c, count(c+7)-1)
- else
- while(turtle.detectDown())do
- turtle.digDown()
- sleep(1)
- end
- turtle.placeDown()
- select(c)
- sleep(1)
- if(turtle.suckDown(turtle.getItemSpace(c)) == false)then
- print("suckDown false sleep 30s")
- select(c+7)
- turtle.digDown()
- sleep(30)
- os.reboot()
- end
- select(c+7)
- turtle.digDown()
- end
- end
- select(c)
- turtle.placeDown()
- end
- return true
- end
- function savemygoto()
- print("savemygoto :"..fakeX..","..fakeY..","..fakeZ..","..fakeFacing..","..fakeC)
- --sleep(3)
- local tab = split(fileGet(dataProjectFilePath), "\n")
- local out = ""
- for i=1, table.getn(tab) do
- if((fakeY+1) == i)then
- if(fakeX == 0)then
- out = out.."0"..string.sub(tab[i],2).."\n"
- elseif(fakeX == string.len(tab[i])-1)then
- out = out..string.sub(tab[i],1, string.len(tab[i])-1).."0".."\n"
- else
- out = out..string.sub(tab[i],1, fakeX).."0"..string.sub(tab[i], fakeX+2).."\n"
- end
- else
- out = out..tab[i].."\n"
- end
- end
- fileSet(dataProjectFilePath, out)
- fileSet("mygoto", fakeX..","..fakeY..","..fakeZ..","..fakeFacing..","..fakeC)
- end
- function mygoto()
- --print("mygoto"..fakeX..","..fakeY..","..fakeZ..","..fakeFacing)
- --print("mygoto"..posX..","..posY..","..posZ..","..facing)
- --sleep(5)
- testFuel()
- testInvPrint()
- if(posZ < fakeZ)then
- while(up()==false)do
- sleep(5)
- end
- posZ = posZ + 1
- setGlobals()
- return true
- end
- if(facing == "n")then
- if(posX < fakeX)then
- while(go()==false)do
- sleep(5)
- end
- posX = posX + 1
- setGlobals()
- return true
- end
- end
- if(facing == "s")then
- if(posX > fakeX)then
- while(go()==false)do
- sleep(5)
- end
- posX = posX - 1
- setGlobals()
- return true
- end
- end
- if(facing == "e")then
- if(posY < fakeY)then
- while(go()==false)do
- sleep(5)
- end
- posY = posY + 1
- setGlobals()
- return true
- end
- end
- if(facing == "w")then
- if(posY > fakeY)then
- while(go()==false)do
- sleep(5)
- end
- posY = posY - 1
- setGlobals()
- return true
- end
- end
- if(facing == "n")then
- if(posY < fakeY)then
- right()
- facing = "e"
- setGlobals()
- return true
- elseif(posY > fakeY)then
- left()
- facing = "w"
- setGlobals()
- return true
- end
- end
- if(facing == "s")then
- if(posY < fakeY)then
- left()
- facing = "e"
- setGlobals()
- return true
- elseif(posY > fakeY)then
- right()
- facing = "w"
- setGlobals()
- return true
- end
- end
- if(facing == "e")then
- if(posX < fakeX)then
- left()
- facing = "n"
- setGlobals()
- return true
- elseif(posX > fakeX)then
- right()
- facing = "s"
- setGlobals()
- return true
- end
- end
- if(facing == "w")then
- if(posX < fakeX)then
- right()
- facing = "n"
- setGlobals()
- return true
- elseif(posX > fakeX)then
- left()
- facing = "s"
- setGlobals()
- return true
- end
- end
- if(fakeX == posX and fakeY == posY and fakeZ == posZ)then
- print("fs.delete(mygoto)")
- fs.delete("mygoto")
- sleep(0.2)
- if(fs.exists("mygoto"))then
- print("Fukin fs.delete de merde")
- print("Write 'fuck' plz")
- input = read()
- if(input == "fuck")then
- print("ty :'(")
- sleep(2)
- shell.exit()
- else
- sleep(20)
- shell.exit()
- end
- end
- return true
- end
- if(facing == "n")then
- right()
- facing = "e"
- setGlobals()
- return false
- end
- if(facing == "s")then
- left()
- facing = "e"
- setGlobals()
- return false
- end
- if(facing == "e")then
- left()
- facing = "n"
- setGlobals()
- return false
- end
- if(facing == "w")then
- right()
- facing = "n"
- setGlobals()
- return false
- end
- return false
- end
- function gpsScan()
- if(isPair(posZ))then -- si Z est pair (on s'ecarte de Y)
- if(isPair(posY))then -- si Y est pair (on s'ecarte de X)
- if(facing == "n" and posX == sizeX - 1 and posY == sizeY - 1)then -- time to get down
- print("get down ")
- if(posZ == sizeZ - 1)then
- finis()
- end
- left()
- facing = "w"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(down())then
- posZ = posZ + 1
- setGlobals()
- shaundy("sendNewLine") ---------------------
- else
- return false
- end
- elseif(facing == "n")then
- -- 1
- if(posX < sizeX - 1)then
- if(go())then
- posX = posX + 1
- setGlobals()
- else
- return false
- end
- else
- right()
- facing = "e"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(go())then
- posY = posY + 1
- setGlobals()
- else
- return false
- end
- end
- elseif(facing == "e")then
- -- 2
- if(posX == 0)then
- left()
- facing = "n"
- setGlobals()
- if(go())then
- posX = posX + 1
- setGlobals()
- else
- return false
- end
- end
- end
- else -- si Y est impaire (on s'approhe X)
- if(facing == "s" and posX == 0 and posY == sizeY - 1)then -- time to get down
- print("get down ")
- if(posZ == sizeZ - 1)then
- finis()
- end
- right()
- facing = "w"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(down())then
- posZ = posZ + 1
- setGlobals()
- shaundy("sendNewLine") ---------------------
- else
- return false
- end
- elseif(facing == "s")then
- -- 3
- if(posX > 0)then
- if(go())then
- posX = posX - 1
- setGlobals()
- else
- return false
- end
- else
- left()
- facing = "e"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(go())then
- posY = posY + 1
- setGlobals()
- else
- return false
- end
- end
- elseif(facing == "e")then
- -- 4
- if(posX == sizeX - 1)then
- right()
- facing = "s"
- setGlobals()
- if(go())then
- posX = posX - 1
- setGlobals()
- else
- return false
- end
- end
- end
- end
- else -- si Z est impaire (on s'approhe Y)
- if(isPair(posY))then -- si Y est pair (on s'approche de X)
- if(facing == "s" and posX == 0 and posY == 0)then -- time to get down
- print("get down ")
- if(posZ == sizeZ - 1)then
- finis()
- end
- left()
- facing = "e"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(down())then
- posZ = posZ + 1
- setGlobals()
- shaundy("sendNewLine") ---------------------
- else
- return false
- end
- elseif(facing == "s")then
- -- 5
- if(posX > 0)then
- if(go())then
- posX = posX - 1
- setGlobals()
- else
- return false
- end
- else
- right()
- facing = "w"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(go())then
- posY = posY - 1
- setGlobals()
- else
- return false
- end
- end
- elseif(facing == "w")then
- -- 6
- if(posX == sizeX - 1)then
- left()
- facing = "s"
- setGlobals()
- if(go())then
- posX = posX - 1
- setGlobals()
- else
- return false
- end
- end
- end
- else -- si Y est impaire (on s'ecarte X)
- if(facing == "s" and posX == 0 and posY == 0)then -- time to get down
- print("get down ")
- if(posZ == sizeZ - 1)then
- finis()
- end
- left()
- facing = "e"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(down())then
- posZ = posZ + 1
- setGlobals()
- shaundy("sendNewLine") ---------------------
- else
- return false
- end
- elseif(facing == "n")then
- -- 7
- if(posX < sizeX - 1)then
- if(go())then
- posX = posX + 1
- setGlobals()
- else
- return false
- end
- else
- left()
- facing = "w"
- setGlobals()
- shaundy("sendLine") ---------------------
- if(go())then
- posY = posY - 1
- setGlobals()
- else
- return false
- end
- end
- elseif(facing == "w")then
- -- 8
- if(posX == 0)then
- right()
- facing = "n"
- setGlobals()
- if(go())then
- posX = posX + 1
- setGlobals()
- else
- return false
- end
- end
- end
- end
- end
- return true
- end
- function cutDataProj()
- input = fileGet(dataProjectFilePath)
- if(isPair(fakeZ))then
- fileSet(dataProjectFilePath, string.sub(input, 2))
- else
- fileSet(dataProjectFilePath, string.sub(input, 0, string.len(input)-1))
- end
- end
- function getNoZero(str)
- local c = "0"
- for i=1, string.len(str) do
- c = string.sub(str, i,i)
- if(c ~= "0")then
- fakeX = i-1
- fakeC = c
- return true
- end
- end
- return false
- end
- function getNoZeroRev(str)
- local c = "0"
- for i=string.len(str), 1 , -1 do
- c = string.sub(str, i,i)
- if(c ~= "0")then
- fakeX = i-1
- fakeC = c
- return true
- end
- end
- return false
- end
- function gpsPrint()
- fakeX = 0
- fakeY = 0
- local tab = split(fileGet(dataProjectFilePath), "\n")
- if(isPair(fakeZ))then
- for i=1, table.getn(tab) do
- fakeY = i-1
- if(isPair(fakeY))then
- if(getNoZero(tab[i]) == true)then
- return savemygoto()
- end
- else
- if(getNoZeroRev(tab[i]) == true)then
- return savemygoto()
- end
- end
- end
- else
- for i=table.getn(tab), 1, -1 do
- fakeY = i-1
- if(isPair(fakeY))then
- if(getNoZero(tab[i]) == true)then
- return savemygoto()
- end
- else
- if(getNoZeroRev(tab[i]) == true)then
- return savemygoto()
- end
- end
- end
- end
- fakeZ = fakeZ+1
- shaundy("getdata")
- return gpsPrint()
- end
- -- __ __ _ ____
- -- | \/ | __ _(_)_ __ / /\ \
- -- | |\/| |/ _` | | '_ \| | | |
- -- | | | | (_| | | | | | | | |
- -- |_| |_|\__,_|_|_| |_| | | |
- -- \_\/_/
- stop=false
- args = { ... }
- if( args[1]~= null)then
- sleep(0.2)
- fileSet(dataFilePath, "")
- sleep(0.2)
- fs.delete(dataFilePath)
- sleep(0.2)
- fileSet("p"..args[1], "")
- sleep(0.2)
- fs.delete("p"..args[1])
- sleep(0.2)
- fileSet("p"..args[1].."names", "")
- sleep(0.2)
- fs.delete("p"..args[1].."names")
- sleep(0.2)
- fs.delete("names")
- sleep(0.2)
- fs.delete("mygoto")
- sleep(0.2)
- else
- sizeX = 0
- sizeY = 0
- sizeZ = 0
- projectName = ""
- scanOrPrint = "scan"
- posX = 0
- posY = 0
- posZ = 0
- facing = "n"
- dataProjectFilePath = ""
- if(fs.exists(dataFilePath))then
- getGlobals()
- else
- init()
- end
- fakeX = posX
- fakeY = posY
- fakeZ = posZ
- fakeFacing = facing
- fakeC = "0"
- testFuel()
- if(scanOrPrint == "print")then
- initPrint()
- else
- initScan()
- end
- checkLabel()
- i = 0
- stopCounter = 1
- gpsFalseCounter = 0
- if(fs.exists("mygoto"))then
- if(fakeX == posX and fakeY == posY and fakeZ == posZ and fakeFacing == facing)then
- getmygoto()
- end
- end
- while(stop==false)do
- if(stopCounter < 2)then
- stopCounter = 25
- checkStop()
- end
- stopCounter = stopCounter - 1
- if(fs.exists("mygoto"))then
- mygoto()
- else
- if(gpsFalseCounter == 0) then
- --print("scan/print test")
- if(scanOrPrint == "scan")then
- downScaner()
- testFuel()
- else
- testFuel()
- printTest()
- end
- end
- if(scanOrPrint == "print")then
- gpsPrint()
- else
- if(gpsScan()==false)then
- gpsFalseCounter = gpsFalseCounter + 1
- print("gps false "..gpsFalseCounter)
- sleep(2)
- else
- gpsFalseCounter = 0
- end
- end
- end
- sleep(0.2)
- end
- end
Add Comment
Please, Sign In to add comment