8 posts
Posted 30 March 2013 - 03:35 PM
Hi,
I wrote
this program and whenever I try to run it, I get the error in the title. Even if I change the program/add more lines I keep getting the same error. It's probably something really simple, but I can't find it. Help is greatly appreciated :)/>
7508 posts
Location
Australia
Posted 30 March 2013 - 03:37 PM
what do these functions do? can you please post the code?
check.whole(z)
check.positive(z)
8 posts
Posted 30 March 2013 - 03:39 PM
what do these functions do? can you please post the code?
check.whole(z)
check.positive(z)
The code for the API functions are in the commented links, but
here and
here are the links. Basically it checks to see if the variable is whole and positive.
7508 posts
Location
Australia
Posted 30 March 2013 - 03:44 PM
oh oops, so used to not reading peoples comments that I didn't even notice them…
gimme a sec.
7508 posts
Location
Australia
Posted 30 March 2013 - 03:51 PM
ok so I cannot seem to replicate the problem.
however I do get an error for the function
checkSlotyou must declare the slot variable above this function.
Side Note: Here is a better CheckAPI
Spoiler
function even(var)
return var % 2 == 0 -- % is shorthand for math.fmod
end
function odd(var)
return not var % 2 == 0
end
function whole(var)
return var % 1 == 0
end
function positive(var)
return var >= 0 -- alternatively you could do var == math.abs(var)
end
8 posts
Posted 30 March 2013 - 04:00 PM
ok so I cannot seem to replicate the problem.
however I do get an error for the function
checkSlotyou must declare the slot variable above this function.
Side Note: Here is a better CheckAPI
Spoiler
function even(var)
return var % 2 == 0 -- % is shorthand for math.fmod
end
function odd(var)
return not var % 2 == 0
end
function whole(var)
return var % 1 == 0
end
function positive(var)
return var >= 0 -- alternatively you could do var == math.abs(var)
end
Thanks for the better API. Just wanted to point out that in the odd function you provided, it's missing a check for a whole number (e.g. 1.5 would be considered odd). But that's an easy fix.
8 posts
Posted 30 March 2013 - 04:01 PM
Also, declaring the slot variable before the function seems to have solved the problem. Thanks :)/>
7508 posts
Location
Australia
Posted 30 March 2013 - 04:08 PM
Thanks for the better API. Just wanted to point out that in the odd function you provided, it's missing a check for a whole number (e.g. 1.5 would be considered odd). But that's an easy fix.
Oh yes, sorry I did miss that off. like you said, easy fix
return not even(var) and (var % 1 == 0)
but iirc your old whole was a little wonky because you were checking the % came to 0.5 which means it wouldn't have been whole.
Also, declaring the slot variable before the function seems to have solved the problem. Thanks :)/>
Cool cool, no problems.