blockly

Wall (Blockly Lua)

Nov 12th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. -- Blockly source: http://blockly-lua.appspot.com/static/apps/code/index.html#w5yeux
  2.  
  3. function create_wall(instructions)
  4.   for _, row in ipairs(instructions) do
  5.     for _, slot_number in ipairs(row) do
  6.       if not turtle.select(slot_number) then
  7.         return 'Unable to select slot #' .. slot_number
  8.       end
  9.       if not turtle.place() then
  10.         return 'Unable to place item from slot #' .. slot_number
  11.       end
  12.       turtle.turnRight()
  13.       if not turtle.forward() then
  14.         return 'Unable to move forward.'
  15.       end
  16.       turtle.turnLeft()
  17.     end
  18.     turtle.turnRight()
  19.     for count = 1, math.floor(#row) do
  20.       if not turtle.back() then
  21.         return 'Unable to move backward.'
  22.       end
  23.     end
  24.     turtle.turnLeft()
  25.     if not turtle.up() then
  26.       return 'Unable to move up.'
  27.     end
  28.   end
  29.   for count2 = 1, math.floor(#instructions) do
  30.     if not turtle.down() then
  31.       return 'Unable to move backward.'
  32.     end
  33.   end
  34.   return 'Done.'
  35. end
  36.  
  37.  
  38. print(create_wall(({({1, 2, 1, 2, 1}), ({2, 1, 2, 1, 2})})))
Advertisement
Add Comment
Please, Sign In to add comment