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