Advertisement
Plazter

gps

Mar 31st, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. turtlemove = {}
  2.  
  3. local ALLCMDS=fbudlrxsg
  4. function turtlemove.doString(str, checkFuel, refuel, fuelRetLocation)
  5.   local function fuelCheck()
  6.     --TODO
  7.   end
  8.   local pos=0
  9.   local str = string.lower(str)
  10.   while pos <= string.len(str) do
  11.     pos = pos+1
  12.     fuelCheck()
  13.     local c = string.sub(str,pos,pos)
  14.     if string.find(ALLCMDS,c,1,true) then
  15.       if string.find("fbudlr",c,1,true) then
  16.         if c=="f" then
  17.           while not turtle.forward() do os.sleep(0.01) end
  18.         elseif c=="b" then
  19.           while not turtle.back() do os.sleep(0.01) end
  20.         elseif c=="u" then
  21.           while not turtle.up() do os.sleep(0.01) end
  22.         elseif c=="d" then
  23.           while not turtle.down() do os.sleep(0.01) end
  24.         elseif c=="l" then
  25.           while not turtle.turnLeft() do os.sleep(0.01) end
  26.         elseif c=="r" then
  27.           while not turtle.turnRight() do os.sleep(0.01) end
  28.         end
  29.       elseif c=="x" then
  30.         local numstr = ""
  31.         while pos <= string.len(str) do
  32.           pos = pos + 1
  33.           c2 = string.sub(str,pos,pos)
  34.           -- break check
  35.           if c2 == "[" then break end
  36.           -- errorcheck
  37.           if not string.find("0123456789",c2,1,true) then error("Unexpected character "..c2.." at position "..pos.." in repetition count") end
  38.           numstr = numstr .. c2
  39.         end
  40.         local pos_b = pos
  41.         local reps = tonumber(numstr)
  42.         if reps == nil then error("Repeated section at postition "..pos.." has no repetition count") end
  43.         while true do
  44.           pos=pos+1
  45.           c3=string.sub(str,pos,pos)
  46.           if c3=="]" then break end
  47.           if pos > string.len(str) then error("Repeated section not closed by position "..pos) end
  48.         end
  49.         local cmdstr = string.sub(str,pos_b,pos)
  50.         for i=1, reps do
  51.           turtlemove.doString(cmdstr)
  52.         end
  53.       else
  54.         error("Unimplemented character "..string.sub(str,pos,pos).." at position "..pos)
  55.       end
  56.     else
  57.       error("Unexpected character "..string.sub(str,pos,pos).." at position "..pos)
  58.     end
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement