odd and even

odd and even

bhnh
Advocate Advocate
1,871 Views
5 Replies
Message 1 of 6

odd and even

bhnh
Advocate
Advocate
Is there a simple way in MAXScript to determine whether a number value is odd or even? In languages I'm familiar with, modolo is used; divide the number by two and if the answer's not an integer then it's odd.
0 Likes
1,872 Views
5 Replies
Replies (5)
Message 2 of 6

Steve_Curley
Mentor
Mentor
mod (modulo) exists in MaxScript as

mod <number1> <number2>
Which returns a floating point number as the result.

e.g.

if (mod a 2) != 0 then
blah

Is that what you were after?

That (and other similar functions) are on the "Number Values" help page.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 6

bhnh
Advocate
Advocate
Exactly! Thanks, Steve.
0 Likes
Message 4 of 6

Steve_Curley
Mentor
Mentor
These might be useful. They probably need some error handling to account for a missing parameter but should serve as a starting point.


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 6

bhnh
Advocate
Advocate
Thanks. Upon reading your first post I immediately tried this out...

fn evalNum a =
(
if(mod a 2) != 0 then
messagebox "odd number" else
messagebox "even number"
)

evalNum 8
evalNum 7


Works a charm. For what I'm thinking of the Boolean return is the obvious way to go. Typically, when I get enthused about something I tend to be more impatient than methodical.
0 Likes
Message 6 of 6

Steve_Curley
Mentor
Mentor
Hehe - me too, on occasion 🙂

The Boolean returned value is the way to go for normal use, but the Messagebox version can be useful for debugging. Easy enough to have both in the script and comment/uncomment as required. There may even be a way to conditionally define them based on a variable (or constant) value, but I've not looked into that.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes