Discussion and Support

Skip to content

It is currently Wed Jan 17, 2018 1:26 pm 

Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Cave Troll
Joined: Sun Mar 22, 2015 2:57 pm
Posts: 46
 Post subject: Modulo Macro Function
PostPosted: Fri Oct 20, 2017 2:22 pm 
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.

[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  Offline
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7982
Location: Bay Area
 Post subject: Re: Modulo Macro Function
PostPosted: Fri Oct 20, 2017 6:20 pm 
You can use math.mod(dividend,divisor). The wiki has it plain ol' mod(). This will work for versions and later. You can see the post about it along with the other added math functions here: viewtopic.php?f=1&t=26714#p263473


User avatar  Offline
Cave Troll
Joined: Sun Mar 22, 2015 2:57 pm
Posts: 46
 Post subject: Re: Modulo Macro Function
PostPosted: Mon Oct 23, 2017 3:46 pm 
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.

Display posts from previous:  Sort by  
Reply to topic  [ 3 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman