控制问题

我遇到了控制语句的问题。我刚刚开始编程。


math.randomseed(os.time())
answers = {
123,
132,
231,
213,
321,
312
}
outcomes = ( answers[ math.random( #answers ) ] )
print("What is your first guess?")
io.write("Guess#1: \n")
g1 = io.read()
onetwothree()
function onetwothree()
if o = 123 and g1 = 321 then
print("You have no numbers correct")
end
end

os.execute("PAUSE")

当我在我的 IDE 中运行这段代码时,它会显示以下内容:

>lua -e "io.stdout:setvbuf 'no'" "Mastermind.lua"
lua: Mastermind.lua:25: 'then' expected near '='
>Exit code: 1

顺便说一下,在我的代码中,第 25 行是这样的:

if o = 123 and g1 = 321 then

我该如何修复这个问题,发生了什么?

点赞
用户1783752
用户1783752

问题是你使用了 = 做比较而不是 ==

将你的条件改为:

if o == 123 and g1 == 321 then
2013-11-03 18:44:34