Advertisement
chopstyix

levelv1

Dec 15th, 2013
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. -- Function's Start Here
  2. function level(x,y)
  3.     -- Turn = 0 ; Turn Right
  4.     -- Turn = 1 ; Turn Left
  5.    
  6.     x = tonumber(x) -- Converts string to int
  7.     y = tonumber(y) -- Converts string to int
  8.    
  9.     turn = 0
  10.     myx = 0
  11.     myy = 0
  12.    
  13.     while ( myy < y) do
  14.         while ( myx < x) do
  15.             turtle.dig()
  16.             turtle.forward()
  17.             myx = myx + 1
  18.         end
  19.        
  20.         if (myy < (y-1)) then
  21.             if (turn == 0) then
  22.                 myx = 0
  23.                 myx = myx +1
  24.                 turtle.turnRight()
  25.                 turtle.dig()
  26.                 turtle.forward()
  27.                 turtle.turnRight()
  28.                 turn = 1
  29.             elseif (turn == 1) then
  30.                 myx = 0
  31.                 myx = myx +1
  32.                 turtle.turnLeft()
  33.                 turtle.dig()
  34.                 turtle.forward()
  35.                 turtle.turnLeft()
  36.                 turn = 0
  37.             else
  38.                 print("Error! How did you do that?")
  39.             end
  40.         end
  41.        
  42.         if (myy < (y-1)) then -- Newly Added
  43.         turtle.forward()
  44.         end
  45.        
  46.         myy = myy + 1
  47.     end
  48.    
  49.     -- Turn = 0; Turtle is away from starting location.
  50.     -- Turn = 1; Turtle is close to starting location.
  51.    
  52.     myx = 0
  53.     myy = 0
  54.    
  55.     if (turn == 0) then -- Return to starting location
  56.         turtle.turnRight()
  57.         turtle.turnRight()
  58.         turtle.forward()
  59.         while ( myx < (x-2)) do
  60.             turtle.forward()
  61.             myx = myx + 1
  62.         end
  63.         turtle.turnRight()
  64.         while (myy < (y-1)) do
  65.             turtle.forward()
  66.             myy = myy + 1
  67.         end
  68.         turtle.turnLeft() -- This indicates it has returned to it's starting location.
  69.         turtle.forward()
  70.         turtle.turnLeft()
  71.         turtle.turnLeft()
  72.     elseif (turn == 1) then
  73.         turtle.turnRight()
  74.         while (myy < (y-1)) do
  75.             turtle.forward()
  76.             myy = myy + 1
  77.         end
  78.         turtle.turnLeft() -- This indicates it has returned to it's starting location.
  79.         turtle.forward()
  80.         turtle.turnLeft()
  81.         turtle.turnLeft()
  82.     else
  83.         print("Error!")
  84.     end
  85. end
  86.  
  87.  
  88. -- Main Script
  89.  
  90. x = 0
  91. y = 0
  92. z = 0
  93.  
  94. myz = 0
  95.  
  96. print("What is x?")
  97. x = io.read()
  98.  
  99. print("What is y?")
  100. y = io.read()
  101.  
  102. print("What is z?")
  103. z = io.read()
  104.  
  105. z = tonumber(z)
  106.  
  107. while (myz < z) do
  108. level(x,y)
  109.     if(myz < (z-1)) then
  110.     turtle.digDown()
  111.     turtle.down()
  112.     end
  113. myz = myz + 1
  114. end
  115.  
  116. -- Start returning back to surface!
  117. myz = 0
  118. while(myz < z) do
  119.     turtle.up()
  120.     myz = myz + 1
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement