【发布时间】:2014-03-10 01:42:18
【问题描述】:
我创建了一个小程序,询问您希望采矿龟开采的长度和高度。但是,当我在高级计算机中运行它时,它让我提示输入长度、宽度和高度,但随后出现错误。错误如下:
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的function Length()定义 -
@Schollii 我已经修改了我的代码,我不太明白你所说的while循环,如果可以的话,你会发布一些代码吗?
-
@hjpotter92 @ Schollii 我再次修改了我的代码,而不是 while 循环我使用了重复循环,但现在 CC 告诉我我正在索引一个 nil 值,请重新阅读我的问题 谢谢你
-
@Schollii 好的,我想通了!上次编辑后我的代码很好,我忘了把它放在海龟上哈哈!
标签: lua minecraft computercraft