If statement 无法正确执行if语句

If statement 无法正确执行if语句,if-statement,lua,If Statement,Lua,这已经困扰了我很长一段时间,我一直在制作一个程序,只要你输入一个特定的密码,它就会执行一个动作。我不断收到一个错误:4:“预期”或“如果预期”请帮助 textutils.SlowPrint("type the password") --This is a W.I.P and it is in a basic stage! pass = ImCool setCursorPos.(4,5) input.read(*) --problem is here if input = pass then p

这已经困扰了我很长一段时间,我一直在制作一个程序,只要你输入一个特定的密码,它就会执行一个动作。我不断收到一个错误:4:“预期”或“如果预期”请帮助

 textutils.SlowPrint("type the password")
--This is a W.I.P and it is in a basic stage!
pass = ImCool
setCursorPos.(4,5)
input.read(*)
--problem is here
if input = pass then
print("You did it"!)

当您尝试检查是否相等时,请使用
=
运算符,如下所示:

if input == pass then
    print("You did it")
end
您现在正在使用
=

您的代码还有其他打字错误-在
setCursorPos
之后有一个
在双引号之外。
ImCool
-这是符号还是字符串?如果是字符串,它应该在双引号中


我不确定是否使用了
输入。read(*)
行-它似乎不正确,但我已经有一段时间没有使用Lua了。我记得使用
io.read()
在Lua中获取命令行输入。

我不是Lua专家,但当您将它分配给
pass
时,似乎应该在
ImCool
周围加上引号:

pass = "ImCool"
我知道您的问题发生在后面的代码行中,但类似这样的错误可能会扰乱解析器

检查初始化字符串变量的字符串部分


另外,我不知道在复制代码时它是否被切断,但您可能需要在if语句后使用
end
。您可能还打算在if语句上使用
==
运算符,而不是
=
。有关详细信息,请参阅。

这不是有效的Lua代码。