Advertisement
Guest User

help me plz

a guest
Jan 5th, 2025
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | Source Code | 0 0
  1. ---@diagnostic disable: undefined-global
  2. function startAll()
  3.  
  4.     print("cual es tu anchura")
  5.     local ancho = read()
  6.     ancho = tonumber(ancho)
  7.     while checkCorrectDataType(ancho) do
  8.         print("--------------------------------")
  9.         print("tu anchura tiene que ser un numero")
  10.         print("cual es tu anchura")
  11.         print("--------------------------------")
  12.         ancho = read()
  13.         ancho = tonumber(ancho)
  14.  
  15.     end
  16.  
  17.     print("cual es tu largo")
  18.     local largo = read()
  19.     largo = tonumber(largo)
  20.     while checkCorrectDataType(largo) do
  21.         print("--------------------------------")
  22.         print("tu largo tiene que ser un numero")
  23.         print("cual es tu largo")
  24.         print("--------------------------------")
  25.         largo = read()
  26.         largo = tonumber(largo)
  27.  
  28.     end
  29.  
  30.     print("cual es tu altura")
  31.     local alto = read()
  32.     alto = tonumber(alto)
  33.     while checkCorrectDataType(alto) do
  34.         print("--------------------------------")
  35.         print("tu altura tiene que ser un numero")
  36.         print("cual es tu altura")
  37.         print("--------------------------------")
  38.         alto = read()
  39.         alto = tonumber(alto)
  40.  
  41.     end
  42.  
  43.     dig3d(ancho, largo, alto)
  44.  
  45. end
  46.  
  47. function dig3d(ancho, largo, alto)
  48.     local currentLayer = 0
  49.     local anchoInicial = ancho
  50.     for i = 1, alto, 1 do
  51.         dig2d(largo, ancho, currentLayer, anchoInicial)
  52.         turtle.digUp()
  53.         turtle.up()
  54.         currentLayer = currentLayer + 1
  55.     end
  56.     for i = alto, 1, -1 do
  57.         turtle.down()
  58.  
  59.     end
  60.  
  61. end
  62.  
  63. function checkCorrectDataType(input)
  64.  
  65.     return input == nil
  66.  
  67. end
  68.  
  69. function resetPosition(ancho, largo)
  70.  
  71.     if ancho % 2 == 0 then
  72.         turtle.turnRight()
  73.         for i = 1, ancho, 1 do
  74.             turtle.forward()
  75.         end
  76.         turtle.turnRight()
  77.  
  78.     else
  79.         turtle.turnLeft()
  80.         for i = 1, ancho, 1 do
  81.             turtle.forward()
  82.  
  83.         end
  84.         turtle.turnRight()
  85.         for i = 1, largo, 1 do
  86.             turtle.back()
  87.  
  88.         end
  89.  
  90.     end
  91.  
  92. end
  93. -- working good
  94. function dig2d(largo, ancho, currentLayer, anchoInicial)
  95.     local temp = ancho
  96.     primeraMinada = ancho
  97.     while temp > 0 do
  98.         if temp == primeraMinada then
  99.             digLargo(largo, currentLayer, anchoInicial, temp)
  100.         else
  101.             giro()
  102.             digLargo(largo - 1, currentLayer, anchoInicial, temp)
  103.  
  104.         end
  105.  
  106.         temp = temp - 1
  107.     end
  108.     resetPosition(ancho, largo)
  109.  
  110. end
  111.  
  112. -- working always
  113. function giro()
  114.  
  115.     turtle.turnRight()
  116.     if turtle.detect() == true then
  117.         turtle.dig()
  118.         turtle.forward()
  119.         turtle.turnRight()
  120.     else
  121.         turtle.turnRight()
  122.         turtle.turnRight()
  123.         turtle.dig()
  124.         turtle.forward()
  125.         turtle.turnLeft()
  126.  
  127.     end
  128.  
  129. end
  130.  
  131. -- working good
  132. function digLargo(largo, currentLayer, anchoInicial, temp)
  133.     while largo > 0 do
  134.         if turtle.detect() == false then
  135.             turtle.forward()
  136.             largo = largo - 1
  137.         else
  138.             turtle.dig()
  139.  
  140.         end
  141.  
  142.     end
  143.  
  144. end
  145.  
  146. startAll()
  147.  
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement