Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

Cannot use Nested Macro to determine Number of Dice

I have a macro that computes the number of dice lost due to damage (Shadowrun 5th ed, if you're curious). I call this macro WoundMod. (floor(ceil(@{selected|Physical Damage}/99) * (@{selected|Physical Damage} -1)/3) + floor(@{selected|Stun Damage} /3))) For most characters, it would be: (floor(@{selected|Physical Damage}/3) + floor(@{selected|Stun Damage} /3)) But my character has a positive quality which gives him one "free" point of damage before the wound would take advantage. If I use a roll like: /roll 1d6 + #WoundMod I can see that #WoundMod is calculated properly. Yay! Without wounds, a roll would be: /roll (3 + @{selected|Agility})d6>5 This works. Yay! If I make an ability that then calculates the roll: /roll (3 + @{selected|Agility} - #WoundMod)d6>5 This is expected to work, but yields: There was an error with your formula. Please try again. I have tried a lot of permutations. Changing order, doing all sorts of things. I even tried: /roll ([[1d1]] + #WoundMod)d6>5 Since I had previously proven that /roll1d1+#WoundMod works. I'm running out of ideas.
1381194378
Pat S.
Forum Champion
Sheet Author
Did you double check your formula to make sure everything is in it's place? all you ( ) in the correct spots, your { } also in proper place?
1381195141
Gauss
Forum Champion
Ok...lets simplify this by replacing the @{selected...} with placeholder letters. ( floor(ceil(A/99)) * (A-1) /3 ) + floor(B/3) )) It appears there are two extra parenthesis at the end. The parenthesis after "(A-1)/3" closes the parenthesis in front of "floor" Also, Im not sure why you have floor in the first term. Ceil in the first term will take care of any non-whole numbers. After you correct the parenthesis please post the new version. - Gauss
It seems I have unbalanced parenthesis, but so far this has not resolved the issue...
1381196190

Edited 1381196237
Gauss
Forum Champion
Sean, please post the new version so that I can then troubleshoot the version as you intended it to work. :) - Gauss
1381197409

Edited 1381197532
hehe Well, floor() is because I have to get rid of any partial 1/3rds that remain. ceil() is a math trick: if physical damage is 0, this returns 0 so the multiplication ends up with 0. If physical damage is non-zero (but presumably less than 99), it returns 1, and after multiplication the result is unchanged. This silliness is needed because physical damage could be 0, and floor((0-1)/3) is -1, which is definitely not what we want. Of course, it would be better if the macro language had if statements... maybe I missed something? Anyway, I have solved the issue by not using a macro. My ability buttons will just have to be verbose: /roll [[3 + @{Agility} - (floor(ceil(@{Physical Damage} /99)*(@{Physical Damage} -1)/3)+floor(@{Stun Damage} /3))]]d6>5 This works! However, even after I had fixed my parenthesis, when calling from a macro it would not work. I could do any sort of math on it I wanted, but as soon as I tried to make it the number of dice rolled, it would error: rolling 3+5 +(floor(ceil(0/99) * (0 -1)/3) + floor(0/3)) 3+5+(floor(ceil(0/99)*(0-1)/3)+floor(0/3)) = 8 Above verifies that the macro is interpreted correctly, but wrapping it in () or [[]] with d6>5 at the end produces: Could not determine result type of: [{"type":"M","expr":"(3+5+(floor(ceil(0/99)*(0-1)/3)+floor(0/3)))"},{"type":"C","text":"d6"}] I had hoped to create a suite of macros that would help the other players. *Tried to edit to fix a typo, but ended up creating a new post when I meant to save the edit. So I deleted the empty post, below.
1381198944
Gauss
Forum Champion
Ok, could you please paste exactly the command as it is entered into the chat box? If the command is a macro on a separate line please post what the macro is and the values of any attributes. - Gauss
Just to make sure: Are you using Macros (created in the My Settings tab) or Abilities (created on the Character Sheet). Both are very similar in many regards but don't work 100% the same.
These Macros (My Settings) work for me: #Agility /roll [[3 + @{selected|Agility} - #WoundMod ]]d6>5 #WoundMod (floor(ceil(@{selected|Physical Damage} /99)*(@{selected|Physical Damage} -1)/3)+floor(@{selected|Stun Damage} /3)) Oddly enough the Space before the ]] is required, otherwise it won't work at all. Also make sure there is no Enter or anything at the end of the second macro, that will break it too. From within a Character Sheet they both look a bit different: %Agility: /roll [[3 + @{Agility} - %{Character Name|WoundMod} ]]d6>5 %WoundMod (floor(ceil(@{Physical Damage} /99)*(@{Physical Damage} -1)/3)+floor(@{Stun Damage} /3)) Replace "Character Name" with the actual character name of the Sheet. Or "selected" if you wanna use the selected character.
I had been using an ability which called a macro. I had also done a lot of manual stuff in the chat box, trying to make it work. I didn't know that spaces were important. I also didn't know you could call an ability using % - that may come in handy. Everyone has been very helpful! Thanks! Is there anywhere where I can find a detailed summary of the commands and syntax available for macro programming? I found floor() and ceil() by guessing. I've used the Macro and Dice Reference pages from the Wiki, but there seems to be more functionality than those reveal.
Quatar, I've now had a chance to test what you wrote up and everything works. Thanks again.