jerimo

Do - the ultimate turtle usage program

Mar 7th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. args = {...}
  2.  
  3. -- Load your own API here and replace "turtle" on lines 25 and 28 with your own API names
  4.  
  5. function runProg(program, repititions)
  6.   if repititions == nil then repititions = 1 end
  7.   while repititions > 0 do
  8.   local i = 1
  9.   while i <= #program do
  10.     if program[i] == "(" then
  11.       subProg = {}
  12.       i = i + 1
  13.       while i < #program and program[i] ~= ")" do
  14.         table.insert(subProg, program[i])
  15.         i = i + 1
  16.       end
  17.       if tonumber(program[i + 1]) ~= nil then
  18.         times = tonumber(program[i + 1])
  19.       end
  20.       runProg(subProg, times)      
  21.     elseif t[program[i]] ~= nil then
  22.       if tonumber(program[i+1]) then
  23.         i = i + 1
  24.         for c=1,tonumber(program[i]) do
  25.           turtle[program[i-1]]()
  26.         end
  27.       else
  28.         turtle[program[i]]()
  29.       end
  30.     else
  31.       print("Running: ", program[i], " of type ", type(program[i]))
  32.       os.run( {}, tostring(program[i]))
  33.     end
  34.     i = i + 1
  35.     end
  36.     repititions = repititions - 1
  37.   end
  38.   return i
  39. end
  40.  
  41.  
  42. -- MAIN --
  43. runProg(args, 1)
Advertisement
Add Comment
Please, Sign In to add comment