## modulo

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

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

Bl4ckj4ck
Cave Troll
Posts: 41
Joined: Thu Jul 17, 2008 7:57 am
Location: San Jose, CA

### modulo

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

Or did I miss it, somewhere?

Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

### 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.

khabalox
Cave Troll
Posts: 35
Joined: Tue Jul 28, 2009 1:07 pm

### 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"]``

syntruth
Giant
Posts: 241
Joined: Mon Aug 18, 2008 7:15 pm
Location: Michigan, USA

### Re: modulo

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

Azhrei
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

### Re: modulo

Yeah, pretty silly.

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

Bl4ckj4ck
Cave Troll
Posts: 41
Joined: Thu Jul 17, 2008 7:57 am
Location: San Jose, CA

### 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.

khabalox
Cave Troll
Posts: 35
Joined: Tue Jul 28, 2009 1:07 pm

### 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]``

toyrobots
Dragon
Posts: 278
Joined: Sat Apr 12, 2008 4:17 pm

### Re: modulo

You guys rock!

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

biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

### 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 ]