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

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

modulo

Post by Bl4ckj4ck »

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

Or did I miss it, somewhere?

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

Re: modulo

Post by Rumble »

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

Or did I miss it, somewhere?

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

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

Re: modulo

Post by khabalox »

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

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

Re: modulo

Post by syntruth »

[blinks]

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

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: modulo

Post by Azhrei »

Yeah, pretty silly. :)

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

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

Re: modulo

Post by Bl4ckj4ck »

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.

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

Re: modulo

Post by khabalox »

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.

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Re: modulo

Post by lmarkus001 »

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]

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

Re: modulo

Post by toyrobots »

You guys rock!

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

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

Re: modulo

Post by biodude »

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 ]

Post Reply

Return to “Macros”