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.
You can solve it either by adding brackets around "i%2" (i.e. "(i%2)") or remove "not" and change "==0" to "==1".
You could also do:
if (i%2)!=0 then |
!= means not equals. (I know you probably know, but just for others who don't...)
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.
[Please log in to post a comment]