This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Adrikus's profile picture

Can you fix my problem?

Started by Adrikus, 21 January 2016 - 06:35 PM
Adrikus #1
Posted 21 January 2016 - 07:35 PM
Hello programmers, I have a problem with a program I did in ComputerCraft , could you help me fix it ?, thanks

--"declaracion de variables"
local num1 = ...;

--Funcion que comprueba que el dato sea un numero entero
function isInteger(number)
        local n = tonumber(number);
                if (n ~= nil) then
                        return true;
                else
                        return false;
                end
end
--Funcion que busca la posicion del combustible en la turtle
function buscarCoal()
        local data;
        local pos = -1;
        for i=1,16 do
                data = turtle.getItemDetail(i).name;
                if(data == "minecraft:coal")then
                        pos = i;
                        break;
                end
        end
        return pos;
end

--Función que recarga de combustible la turtle.
function refuel()
local pos = -1;
pos = buscarCoal();
        if (pos~=nil) then
  turtle.select(pos);
  turtle.refuel();
  if (turtle.refuel()) then
   print("Se a llenado el deposito con exito, el carbon estaba en la posicion "..pos);
  end
else
  print("Inserte primero el carbon o carbon vegetal para continuar");
end

end
--funcion para intentar colectarlocal function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
  print( "Mined "..collected.." items." )
end
end
--funcion para intentar picar
function tryDig()
while turtle.detect() do
  if turtle.dig() then
   collect()
   sleep(0.5)
  else
   return false
  end
end
return true
end--Funcion para intentar seguir adelante
function tryForward()
refuel()
while not turtle.forward() do
  if turtle.detect() then
   if not tryDig() then
        return false
   end
  elseif turtle.attack() then
   collect()
  else
   sleep( 0.5 )
  end
end
return true
end

--Dar valor a la variable num1
function escribirValor()
        local value;
        print("Escriba por favor la profundidad de la escalera: ");
        value = read();
        if (isInteger(value) == true) then
                num1 = tonumber(value);
                escalera(num1);
        else
                print("El dato añadido no es un numero.");
        end
end

--Funcion que te devuelve el numero del slot donde esta la cobblestone.
function buscarCobble()
        local data;
        local pos = -1;
        for i=1,16 do
                data = turtle.getItemDetail(i).name;
                if(data == "minecraft:cobblestone")then
                        pos = i;
                        print(i);
                        break;
                end
        end
        return pos;
end

--Empezar a hacer la escalera
function escalera(numero)
        local bucle = numero;
        for i=0,bucle do
                turtle.digDown();
                turtle.down();
                turtle.dig();
                turtle.forward();
                if(turtle.detectUp()) then
                        turtle.digUp();
                end
        end
        salir(bucle);
end

--Funcion que hace salir a la turtle
function salir(bucle)
turtle.turnRight();
turtle.turnRight();
        for i=0,bucle do
                turtle.forward();
  if n<length then
   tryDig();
   if not tryForward() then
        print( "Aborting Tunnel." ):
        break;
   end
  else
   print( "Tunnel complete." )
  end
                if not(turtle.detectDown()) then
                        turtle.select(buscarCobble());
                        turtle.placeDown();
                end
                turtle.up();
        end
end
--Funcion para sacar todos los objetos de la turtle
function finalizar()
for i=1,16 do
  turtle.select(i);
  turtle.drop();
end
turtle.turnLeft();
turtle.turnLeft();
end


refuel();
escribirValor();
finalizar();

print("Programa Finalizado.");

At line 135 <'Name'> Expected

Edited by
Lyqyd #2
Posted 21 January 2016 - 08:27 PM
Moved to Ask a Pro.
Dragon53535 #3
Posted 21 January 2016 - 08:31 PM
Can you tell us what the problem is?
wilcomega #4
Posted 21 January 2016 - 08:37 PM
first thing i spotted is that at line 128 you used a : instead of a ;

but it would be helpfull to post the full error, and to tell us what the goal of the program is
TheOddByte #5
Posted 21 January 2016 - 08:48 PM
I'm going to take a wild guess and say that the function salir is the one causing the problem

function salir( bucle )
    turtle.turnRight();
    turtle.turnRight();
    for i=0,bucle do
        turtle.forward();
        if n < length then --# You're comparing with the variable length, one which I could not find in your code
            tryDig();
            if not tryForward() then
                print( "Aborting Tunnel." ): --# You've put a colon here instead of a semicolon
                break;
            end
        else
            print( "Tunnel complete." )
        end
        if not(turtle.detectDown()) then
            turtle.select(buscarCobble());
            turtle.placeDown();
        end
        turtle.up();
    end
end
I've pointed out the errors I've found in your code, you may try to fix this and see if it solves your problem.