Lua: Why does this get the error: '=' expected near 'bool'?

Viewed 156

I wanted to answer a mathematical question with this. Code:

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

This is probably easy to fix because I started yesterday.

1 Answers

A Lua function call must have parentheses around the arguments, except when there's exactly one argument which is a string literal (as in your require 'math') or a table constructor (using {curly braces}).

Since the variable bool is neither of those exceptions, instead of print bool you need print(bool).

Related