【发布时间】:2019-08-28 23:53:29
【问题描述】:
我尝试用_G. 声明变量,并在函数的末尾放置一个return 语句,就在最后一个“结束”之前。第一个给了我一个错误,另一个没有解决任何问题。
X = 0
Y = 0
Z = 0
BedrockLevel = 0
CurrentLayer = 5
succsess = true
function DigDown(BedrockLevel, CurrentLayer, Z, succsess)
while BedrockLevel == 0 do
succsess = turtle.digDown()
if succsess == false then
succsess = turtle.down()
if succsess == false then
BedrockLevel = Z - 1
else
Z = Z - 1
end
end
succsess = turtle.down()
if succsess == true then
Z = Z - 1
end
end
while Z < BedrockLevel + CurrentLayer do
succsess = turtle.up()
if succsess == true then
Z = Z + 1
end
end
return BedrockLevel, CurrentLayer, Z, succsess
end
DigDown(BedrockLevel, CurrentLayer, Z, succsess)
print(BedrockLevel, X, Y, Z)
预期结果是:打印功能显示:-10 0 0 5,
但它说的是 0 0 0 0。
由于这是在代码顶部分配的值,因此我假设函数不会更改它,即使有 return 语句。
【问题讨论】:
标签: lua