3

我的控制语句有问题。我刚开始编程。


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

我该如何解决这个问题以及发生了什么。

4

1 回答 1

5

问题是您使用=的是比较而不是==.

将您的条件更改为:

if o == 123 and g1 == 321 then
于 2013-11-03T18:44:34.893 回答