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

Program error

Started by Eragon, 09 March 2014 - 09:21 AM
Eragon #1
Posted 09 March 2014 - 10:21 AM
pastebin.com/TgD4BQLL
Help please
Lyqyd #2
Posted 09 March 2014 - 03:20 PM
If you want some help, we're going to need more information. What's the error you're getting, for a start?
Eragon #3
Posted 09 March 2014 - 05:41 PM
oh, sorry bios:339: [string "mining"] :169: 'end' expected ( to close 'if' at line 165)
CometWolf #4
Posted 09 March 2014 - 06:47 PM
Are these errors really that vauge to people, or do they just not bother anymore?

if os.pullEvent ("key",true) then -- this true here does nothing
print("am inceput")
for i=1, n do
  miningadv()
  --you forgot to close this for loop with an end statement.
end
Edited on 09 March 2014 - 05:47 PM
Lyqyd #5
Posted 09 March 2014 - 07:18 PM
Are these errors really that vauge to people, or do they just not bother anymore?

We benefit from the experience of having seen these errors before and having figured out how to deal with them. New users may be trying to program for the first time, and so won't know what to do with an error message. It's much more useful to walk someone through the process you've used to resolve the issue than than to throw an answer at them. In that way, they may be able to solve the next error they come across on their own instead of coming to us for help.

Eragon, I've copied your script and added correct indentation to it. Indentation is useful to visually see where blocks of code start and end. The error message you were getting means that the Lua interpreter was expecting to find an 'end' statement, but didn't. If you look at the bottom of your script where the line number tells you, you'll notice in the below version of it that there is an end to close the for loop, but no end to close the if statement.


write("Cate layere vrei ? : ")
local n=read()
print("Pune in in turtle, cobblestone in slotul 13, ender chest pentru pus itemele in slotul 14, ender chest cu coal in slotul 15 si niste coal in slotul 16, apoi apasa E")
local x=turtle.getFuelLevel()
local o = 10

function getcoal()
    --aia care ia coal de la un ender chest
    turtle.turnRight()
    o=o+1
    turtle.dig()
    turtle.select(15)
    turtle.place()
    turtle.select(16)
    turtle.suck()
    turtle.select(15)
    turtle.dig()
    turtle.turnLeft()
    o=o-1
end

function refuel()
    --functia care asigura ca turtle-ul are fuel
    if x < 1000 then
        turtle.select(16)
        turtle.refuel(16)
        --# we can remove the else here, since it's an empty block.
    end
end

function dropitems()
    --functia care da drop la iteme intr-un ender chest
    turtle.turnRight()
    o=o+1
    turtle.select(14)
    turtle.place()
    for i = 1, 12 do
        turtle.select(i)
        turtle.drop()
    end
    turtle.select(14)
    turtle.dig()
    turtle.turnLeft()
    o=o-1
end

function firstlinie()
    for i = 1, 4 do
        turtle.dig()
        while turtle.dig(true) do
            turtle.dig()
        end
        turtle.up()
        turtle.turnLeft()
        o=o-1
        turtle.select(13)
        turtle.place()
        turtle.turnRight()
        o=o+1
    end
    turtle.dig()
end

function liniesus()
    for i = 1, 4 do
        turtle.dig()
        while turtle.dig(true) do
            turtle.dig()
        end
        turtle.up()
    end
    turtle.dig()
end

function liniejos()
    for i = 1,4 do
        turtle.dig()
        turtle.down()
    end
    turtle.dig()
end

function inapoi()
    turtle.turnLeft()
    o=o-1
    for i = 1, 4 do
        turtle.forward()
        turtle.down()
    end
    turtle.turnRight()
    o=o+1
    turtle.forward()
end

function layer()
    firstlinie()
    for i = 1, 2 do
        turtle.turnRight()
        o=o+1
        turtle.forward()
        turtle.turnLeft()
        o=o-1
        liniejos()
        turtle.turnRight()
        o=o+1
        turtle.forward()
        turtle.turnLeft()
        o=o-1
        liniesus()
    end
    liniesus()
    inapoi()
    sleep(1)
end

function fullinv()
    for i=1,12 do
        if(turtle.getItemCount(i) == 0) then
            return false
        else
            return true
        end
    end
end

function drop()
    if fullinv(true) then
        dropitems()
    end
end

y = turtle.getItemCount(16)

function coal()
    if y < 32 then
        getcoal()
    end
end

function aresume()
    turtle.select(13)
    turtle.placeDown()
    turtle.turnLeft()
    o=o-1
    turtle.place()
    turtle.turnRight()
    o=o+1
end

function resume()
    if o > 10 then
        while o ~= 10 do
            turtle.turnLeft()
            o=o-1
        end
    elseif o < 10 then
        while o ~= 10 do
            turtle.turnRight()
            o=o+1
        end
    end
    turtle.turnLeft()
    for i = 1, 5 do
        turtle.forward()
    end
    turtle.turnRight()
    for i = 1, 5 do
        turtle.down()
    end
end

function miningadv()
    aresume()
    resume()
    drop()
    coal()
    refuel()
    layer()
end

if os.pullEvent ("key",true) then
    print("am inceput")
    for i=1, n do
        miningadv()
    end
Eragon #6
Posted 11 March 2014 - 10:40 PM
Oh, thanks so much i know from the error That I've forgot an end but I didn't know were…. I was a little bit dumb because i was adding an other part to this program and I was thinking there is the problem not at the end. Thanks a lot ! (By the way sorry for my bad English)