我有一个小问题我是 Lua 和 ComputerCraft 的新手。所以我认为我的问题是我太愚蠢了,无法编写 if 语句中的变量更改我将发布我的代码希望你能帮助我解决这个问题 thx
mon = peripheral.wrap("top")
modem = peripheral.wrap("right")
mon.clear()
mon.setCursorPos(1,2)
mon.blit("Pulverizer","0000000000","dddddddddd")
redstone.setOutput("right", true)
Pulverizer = true
mon.setCursorPos(1,4)
mon.write("Furnice","0000000","ddddddd")
redstone.setOutput("left", true)
local Furnice = true
mon.setCursorPos(1,6)
mon.write("Injection Chamber","00000000000000000","ddddddddddddddddd")
local Injection_Chamber = true
redstone.setOutput("top",true)
mon.setCursorPos(1,8)
mon.write("Metalurgig InFuser","000000000000000000","dddddddddddddddddd")
local Metalurgig_InFuser = true
redstone.setOutput("bottom", true)
while true do
event,side,x,y = os.pullEvent("monitor_touch")
if x > 1 and x < 11 and y == 2 and Pulverizer == true then
mon.setCursorPos(1,2)
mon.clearLine()
mon.blit("Pulverizer","0000000000","eeeeeeeeee")
redstone.setOutput("right", false)
Pulverizer = false
elseif x > 1 and x < 11 and y == 2 and Pulverizer == false then
mon.setCoursorPos(1,2)
mon.clearLine()
mon.blit("Pulverizer","0000000000","dddddddddd")
redstone.setOutput("right", true)
Pulverizer = true
end
end
Pastebin 的链接:链接到代码
所以问题出在这部分代码中
if x > 1 and x < 11 and y == 2 and Pulverizer == true then
mon.setCursorPos(1,2)
mon.clearLine()
mon.blit("Pulverizer","0000000000","eeeeeeeeee")
redstone.setOutput("right", false)
Pulverizer = false
Pulverizer 变量不想从 true 更改为 false,因此此代码现在无法激活
elseif x > 1 and x < 11 and y == 2 and Pulverizer == false then
mon.setCoursorPos(1,2)
mon.clearLine()
mon.blit("Pulverizer","0000000000","dddddddddd")
redstone.setOutput("right", true)
Pulverizer = true
而且我不知道为什么这里还有一个来自游戏内镜头的视频链接,所以你可以在视频中看到它变成红色但不再变成绿色