我在计算机技术中使用 Lua 来自动化挖掘。但是,我的程序以前运行良好的海龟,如果遇到lava/flowing_lava/water/flowing_water source
.
在我的程序中,我有很多功能需要管理,例如,燃料管理、隧道、与砾石的碰撞,以及 .. 检测海龟是否遇到“障碍物”。
如果该块只是一个空气块,乌龟继续前进,否则如果该块不是空气块,乌龟挖这个块,如果它面前还有一个块就不会向前移动。问题?我之前引用的四个来源被认为是块,乌龟不能前进。
我尝试在 if 中使用多条件来解决这个问题,但它不起作用,乌龟向前移动并朝任何方向挖掘。
所以我认为这是因为我创建 if 的方式不好,也许是语法(用于连接许多或进入 () )。
如何解决这个问题?
function blockDetection(position, justDetection)
success, detectionBlock = nil
block_name = ""
if position == "right" then
turtle.turnRight()
success, detectionBlock = turtle.inspect()
turtle.turnLeft()
if success then
block_name = detectionBlock.name
if justDetection == true and detectionBlock.name == "minecraft:air" then
block_name = true
elseif justDetection == true and detectionBlock.name ~= "minecraft:air" then
block_name = false
else
end
end
end
end