59 posts
Posted 14 October 2015 - 03:24 PM
I have a problem with this if:
if not fs.getFreeSpace("/") >= 100 then
the return is:
startup:103: attempt to compare boolean with number
Can you please help me?
Thanks
8543 posts
Posted 14 October 2015 - 03:31 PM
The not happens before the comparison. You should remove the not and use < instead of >=.
59 posts
Posted 14 October 2015 - 03:57 PM
Thanks a lot but I don't fully understand why its happened
8543 posts
Posted 14 October 2015 - 06:26 PM
Order of operations. As you can see in the
operator precedence list, the `not` operator has a higher precedence than `>=` does. So, first, the result of the fs.getFreeSpace call is Boolean NOT'd, which would turn any number to a Boolean false value. Then it tries to compare `false >= 100`, which is where the error is thrown. So instead, you should change the comparison operator to make the comparison you're actually interested in, rather than trying to use the opposite comparison and inverting the result (which would work if you used parentheses to force the comparison to happen before the inversion, but there is no good reason to do that).