Modulo Macro Function

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
TheIneffableCheese
Cave Troll
Posts: 64
Joined: Sun Mar 22, 2015 3:57 pm

Modulo Macro Function

Post by TheIneffableCheese »

I have a macro I built quite a while ago for marking elevation on a flying creature. I relied on the "mod" function to isolate the hundreds place, the tens place, and the ones place and then used that information to assign states for each of those positions resulting in a number on the upper right corner of the token. This function was something I found on the Macro reference on the RPTools wiki.

It stopped working mysteriously some time back, and I've just been dealing without it since then. I just decided to revisit it, and when I ran the macro, I got an "undefined function: mod" error in the Chat window. That struck me as odd since I know it worked in the past. I went to the wiki and found the entry for the mod function, but even though there are instructions about syntax, at the top of the page is a note that the function doesn't exist in MapTool.

When did this change? Is there an alternative function to get the same result (i.e., the remainder only from a division operation)?

I'm dropping the script as currently written under a spoiler tag in case reviewing it is helpful.
Spoiler
[h: x=input("NewElevation|0|What is the token's new elevation?")]
[h: abort(x)]

[h: assert(mod(NewElevation, 5) == 0, "Elevation must be divisible by 5")]
[h: assert(NewElevation>=0 && NewElevation<=995, "Elevation must be between 0 and 995")]

[h: selectedToken = getSelectedNames()]

[h: OldElevation = getProperty("Elevation", selectedToken)]

[h: OldHundredsDigit=FLOOR(OldElevation/100)]
[h: OldTensAndOnes=mod(OldElevation, 100)]
[h: OldTensDigit=FLOOR(OldTensAndOnes/10)]
[h: OldOnesDigit=mod(OldTensAndOnes,10)]

[h: NewHundredsDigit=FLOOR(NewElevation/100)]
[h: NewTensAndOnes=mod(NewElevation, 100)]
[h: NewTensDigit=FLOOR(NewTensAndOnes/10)]
[h: NewOnesDigit=mod(NewTensAndOnes,10)]

[h: setState("E"+OldHundredsDigit+"__",0,selectedToken)]
[h: setState("E_"+OldTensDigit+"_",0,selectedToken)]
[h: setState("E__"+OldOnesDigit, 0, selectedToken)]

[h, if(NewHundredsDigit == 0): setState("E"+NewHundredsDigit+"__",0,selectedToken);setState("E"+NewHundredsDigit+"__",1,selectedToken)]
[h, if(NewHundredsDigit == 0 && NewTensDigit == 0): setState("E_"+NewTensDigit+"_",0,selectedToken); setState("E_"+NewTensDigit+"_",1,selectedToken)]
[h, if(NewElevation == 0): setState("E__"+NewOnesDigit, 0, selectedToken); setState("E__"+NewOnesDigit, 1, selectedToken)]

[h: setProperty("Elevation", NewElevation, selectedToken)]

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modulo Macro Function

Post by aliasmask »

You can use math.mod(dividend,divisor). The wiki has it plain ol' mod(). This will work for versions 1.4.0.3 and later. You can see the post about it along with the other added math functions here: http://forums.rptools.net/viewtopic.php ... 14#p263473

User avatar
TheIneffableCheese
Cave Troll
Posts: 64
Joined: Sun Mar 22, 2015 3:57 pm

Re: Modulo Macro Function

Post by TheIneffableCheese »

math.mod worked like a champ - thanks for that.

Could I suggest that the Wiki be updated with this information - perhaps noting that the mod function has been deprecated and maybe point to a new article explaining these new math functions? I would have been able to troubleshoot this myself if the information had been there.

Post Reply

Return to “Macros”