## modulo

**Moderators:** dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

### Re: modulo

Bl4ckj4ck wrote:Is there no modulo command? How am I supposed to find if something is odd or even?

Or did I miss it, somewhere?

There is no modulo command, unfortunately; you'll have to use another trick to find odd/even numbers.

### Re: modulo

Something like this (untested, off the cuff code) might work.

Code: Select all

`[if(myVar/2 == floor(myVar/2)): "myVar is even"; "myVar is odd"]`

### Re: modulo

[

...y-you mean there is no % operator in the math code? :O

*blinks*]...y-you mean there is no % operator in the math code? :O

### Re: modulo

Yeah, pretty silly.

The good news is that JavaScript is just around the corner and it has all that stuff.

The good news is that JavaScript is just around the corner and it has all that stuff.

### Re: modulo

khabalox wrote:Something like this (untested, off the cuff code) might work.Code: Select all

`[if(myVar/2 == floor(myVar/2)): "myVar is even"; "myVar is odd"]`

That should work. Thanks for the idea! Clever, tricksy hobbitses.

### Re: modulo

Bl4ckj4ck wrote:That should work. Thanks for the idea! Clever, tricksy hobbitses.

No problem. I used something similar in my getAbilityMod() UDF for D&D 3.5.

- lmarkus001
- Great Wyrm
**Posts:**1862**Joined:**Sat Mar 29, 2008 12:30 am**Location:**Layfayette Hill, PA

### Re: modulo

My user defined function:

**mod()**Code: Select all

`<!--`

[H: assert(argCount() == 2, "mod() requires two arguments (Variable, Divisor)", 0)]

[H: tVar = arg(0)]

[H: tDiv = arg(1)]

[H: output = tVar - floor( tVar / tDiv ) * tDiv]

-->[R: output]

### Re: modulo

You guys rock!

iMarkus, that works great. I've wanted a Modulus function for quite some time! Thanks!

iMarkus, that works great. I've wanted a Modulus function for quite some time! Thanks!

### Re: modulo

There's a modulo function included in the Lib:Math token ( or try aliasMask's version for a different set of functions, including modulo. )

*"The trouble with communicating is believing you have achieved it"*

[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]