我创建了一个小程序,该程序请求您希望挖矿龟挖掘的长度、宽度和高度。当我在高级电脑上运行它时,它让我提示长度,宽度和高度,但然后我得到一个错误。错误如下:
miner: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
看起来你的任何功能都没有end
,先修复它。如果你正确缩进你的代码,你会看到这个
你也有while count < length do
和else
块。我敢说这不是有效的语法(从未见过它,只是检查了在线ref manual和wiki)。目前还不清楚你是否意味着if count < length do
,但如果真的意味着while
,那么用end
代替else
看起来也不对。仔细看看这段代码。