ColdIV

quickMove

Oct 2nd, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. -- pastebin run FuQ3WvPs 963AtZS3 quickMove
  2. function act(word)
  3.     local command_table = {
  4.         f = turtle.forward,
  5.         b = turtle.back,
  6.         tr = turtle.turnRight,
  7.         tl = turtle.turnLeft,
  8.         ta = turtle.turnAround,
  9.         d = turtle.dig,
  10.         dd = turtle.digDown,
  11.         du = turtle.digUp,
  12.         u = turtle.up,
  13.         dn = turtle.down,
  14.         p = turtle.place,
  15.         pd = turtle.placeDown,
  16.         pu = turtle.placeUp
  17.     }
  18.    
  19.     local w = tostring(word)
  20.     local f = command_table[w]
  21.    
  22.     if f == nil then return false end
  23.    
  24.     succ, err = f()
  25.     if not succ then
  26.         print ("I tried and failed, sorry!")
  27.     end
  28.    
  29.     return succ
  30. end
  31.  
  32.  
  33. function mmove(path)
  34.     for command in string.gmatch(path, '([^,]+)') do
  35.         local num = string.match(command, '%d+') or 1
  36.         local word = string.match(command, '[^%d]+')
  37.  
  38.         for i = 1, num do
  39.             if not act(word) then break end
  40.         end
  41.     end
  42. end
  43.  
  44. local args = {...}
  45. if args[1] == "update" then
  46.     shell.run("pastebin", "run", "FuQ3WvPs 963AtZS3 quickMove")
  47. else
  48.     while true do
  49.         local input = read()
  50.         if input == "q" then break end
  51.         mmove(input)
  52.     end
  53. end
Add Comment
Please, Sign In to add comment