Log In  

here is the code

    for i=1,#tbl do
        if not i%2==0 then
            spr(3,tbl[i],tbl[i+1])
        end
    end

Everything else in the code is fine, so i wont include it.

When run it says "attempt to perform arithmetic on a boolean value", and the error is in the if not line. Tell me why and what to do please.

P#43439 2017-08-19 18:06 ( Edited 2017-08-20 08:07)

You can solve it either by adding brackets around "i%2" (i.e. "(i%2)") or remove "not" and change "==0" to "==1".

P#43440 2017-08-19 18:15 ( Edited 2017-08-19 22:15)

You could also do:

if (i%2)!=0 then

!= means not equals. (I know you probably know, but just for others who don't...)

P#43450 2017-08-20 02:12 ( Edited 2017-08-20 06:14)

This is because 'not' is a unary operator, like negation, and unary operators have very high precedence.

Consider what you'd expect if you wrote...

if -i%2==0 then

If you know C/C++, treat 'not' like the '!' symbol, which is identical in behavior.

P#43456 2017-08-20 04:07 ( Edited 2017-08-20 08:09)

[Please log in to post a comment]