Lua Math.random 和 if 语句
Lua Math.random and if statement
该代码的目的是产生一个随机数,并根据产生的数字执行特定操作。
local x = math.random(1,2)
if x = 1 then
print("x = 1")
else
print("x > 1")
end
然而,当我 运行 代码时,我收到以下错误“'the'” expected near '='”
而且我似乎仍然不明白为什么它不起作用,所以有人可以帮帮我吗? :)
您需要使用双等号 ==
进行相等性测试,=
用于 lua 中的赋值。 http://www.lua.org/pil/3.2.html
该代码的目的是产生一个随机数,并根据产生的数字执行特定操作。
local x = math.random(1,2)
if x = 1 then
print("x = 1")
else
print("x > 1")
end
然而,当我 运行 代码时,我收到以下错误“'the'” expected near '='” 而且我似乎仍然不明白为什么它不起作用,所以有人可以帮帮我吗? :)
您需要使用双等号 ==
进行相等性测试,=
用于 lua 中的赋值。 http://www.lua.org/pil/3.2.html