Lua:为什么会出现错误:“=”expected near 'bool'?

我想用这个来回答一个数学问题。

代码:

require 'math'

bool = 0
e = math.random(1, 101)
f = math.random(1, 101)
c = 0

function dm(a, b)
    d = a % b
    return d%b
end

repeat
    if dm(e, f) == e % f then
        bool = true
    else
        bool = false
        break
    end
    c = c + 1
    e = math.random(1, 101)
    f = math.random(1, 101)
until c == 101

print bool

这可能很容易修复,因为我昨天开始写的。

点赞
用户459640
用户459640

Lua 函数调用必须在参数周围加上括号,除非恰好有一个参数是字符串文本(就像你的 require 'math' 一样)或者是表构造器(使用 { 大括号 })。

由于变量 bool 不属于上述任何一种例外情况,所以你需要使用 print(bool) 而不是 print bool

2020-04-11 13:08:18