【问题标题】:Checking computercraft Lua code to operate a door检查计算机技术 Lua 代码以操作门
【发布时间】:2018-10-15 06:31:13
【问题描述】:

我正在使用一些自定义模块制作保险库,并且正在使用计算机控制门,但我只能打开门而不能关闭。这段代码对吗?

term.setTextColor(colors.yellow)
print("Vault-Tec Door Computer")
term.setTextColor(colors.white)
print("What Command Would You Like To Do?")
term.setTextColor(colors.blue)
print("Vault.Open")
print("Vault.Close")
print("")
term.setTextColor(colors.white)
io.write("Vault-Tec:")
io.close()
    if io.read()=="Vault.Open" then
        term.setTextColor(colors.red)
        print("VAULT DOOR OPENING, PLEASE STAND BACK")
        term.setTextColor(colors.white)
        redstone.setAnalogOutput("bottom", 0)
        sleep(5)
    end
    if io.read()=="Vault.Close" then
        term.setTextColor(colors.red)
        print("SHUTTING VAULT DOOR, PLEASE STAND BACK")
        term.setTextColor(colors.white)
        redstone.setAnalogOutput("bottom", 15)
        sleep(5)
    end

【问题讨论】:

    标签: lua minecraft computercraft


    【解决方案1】:

    您的第一个 if 语句调用 io.read() 并读取输入的任何内容并将其与 Vault.Open 进行比较。您的下一个 if 语句读取 下一个输入的内容,并将其与 Vault.Close 进行比较。您应该只读取一次输入的内容并将其存储在一个变量中,然后您可以在多个地方使用该值。

    .....
    local valutStatus = io.read()
    if valutStatus == "Vault.Open" then
        term.setTextColor(colors.red)
        print("VAULT DOOR OPENING, PLEASE STAND BACK")
        term.setTextColor(colors.white)
        redstone.setAnalogOutput("bottom", 0)
        sleep(5)
    end
    if valutStatus == "Vault.Close" then
        term.setTextColor(colors.red)
        print("SHUTTING VAULT DOOR, PLEASE STAND BACK")
        term.setTextColor(colors.white)
        redstone.setAnalogOutput("bottom", 15)
        sleep(5)
    end
    

    【讨论】:

    • 谢谢,我是 Lua 新手,所以我不知道如何解决它,但我看到你做了什么,你帮助了我:D!
    • 请注意,有时会在此处删除仅代码的答案。您能否通过编辑的方式添加对此问题的解释以及为什么可以解决问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多