1

我创建了一个小程序,询问您希望采矿龟开采的长度和高度。但是,当我在高级计算机中运行它时,它让我提示输入长度、宽度和高度,但随后出现错误。错误如下:

矿工:39:尝试索引?(一个零值)

这是我的代码:

term.clear()
term.setCursorPos(1,1)





write("Length:")
length = read()
print()
write("Confirm:")
ul = read()
print()

write("Width:")
width = read()
print()
write("Confirm:")
uw = read()
print()

write("Height:")
height = read()
print()
write("Confirm:")
uh = read()
print()

local totcount = ul + uw + uh
local subcount = 0




function Length()

repeat 

    turtle.dig()
    turtle.forward()
    length = length - 1
    subcount = subcount + 1

until length == 0
length = ul

end

function Width()

repeat

    turtle.dig()
    turtle.forward()
    width = width - 1
    subcount = subcount + 1

until width == 0
width = uw
end

function Height()
turtle.digDown()
turtle.down()
height = height - 1
subcount = subcount + 1
end

function Turn()

turtle.turnRight()

end



repeat

Length()
Turn()
Width()
Turn()
Length()
Turn()
Width()
Turn()
Height()

until subcount == totcount
4

1 回答 1

2

看起来你的任何功能都没有end,先修复它。如果您正确缩进您的代码,您将看到这一点。

你也有while count < length do一个else块。AFAIK 这不是有效的语法(从未见过它,只是检查了在线参考手册和维基)。目前尚不清楚您是否指的是if count < length do,但如果真的是指,while那么替换elsebyend看起来也不正确。仔细看看那部分代码。

于 2014-03-09T15:11:48.820 回答