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 .
×
Create a free account

Macro help! Need a return a zero if the result is a negative number

In the following script, the attribute "Shield" can be a large number, such as 40. If the 3d12 is rolled, and the result is low, then subtracting the Shield from the roll will net a negative result. I want it to display 0 (or the negative number). Currently, it simply ignores the Shield Attribute - unless the result will be positive. &{template:default}{{name=Disrupter Cannon Blast at @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[3d12 - @{selected|Shield}]]}} Any ideas? THANK YOU!
1555488935

Edited 1555488964
vÍnce
Pro
Sheet Author
Try this @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[ {0,( 3d12 - @{selected|Shield}) }kh1 ]] }}
I got a syntax error: SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-], [+|\-|*|\/|%] or [0-9] but "s" found.
1555515603
GiGs
Pro
Sheet Author
API Scripter
Try this tweak: @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[  {0d0,( 3d12 - @{selected|Shield}) }kh1  ]] }}
Thanks! Still get: SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-], [+|\-|*|\/|%] or [0-9] but "s" found.
1555516982

Edited 1555517019
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Well, the syntax is correct. I'd check the value in your shield attribute to make sure it is actually a number instead of something like "shield:40". I checked the syntax with this test roll: /r {0d0,3d12 - 20}kh1
This works:  @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[ 3d12 - 20]] }} (A negative result from 3d12-20 displays as a negative number) Now I just need to pull the Shield Attribute of the selected token, in place of the "20"
Thanks this works ("0" result on negative numbers): @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[ {0d0,3d12 - 20}kh1]] }} Just need to grab the Shield attribute of the in place of 20.
Guess I will have to use a query. Not as elegant, but OK: &{template:default}{{name=Disrupter Cannon Blast at @{selected|Token_Name}}}!}}} {{attack= [[1d20]]}} {{damage= [[ {0d0,3d12 - ?{Shields?}}kh1]] }}
Thanks everyone. If anyone thinks of a solution, I will keep looking. Again, thanks for your efforts.
1555518807
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Like I said in my post, it sounds to me like you've got erroneous or incorrectly formatted information in your shield attribute. Try just typing @{selected|shield} into chat and see what gets output. There is no difference from a macro standpoint in doing {0d0,3d12 - 20}kh1 vs {0d0,3d12 - @{selected|shield}}kh1 . The only way that doing the attribute call could be causing an issue is if its value is not what you think it is. Additionally, I just noticed that you've got something hinky in your macro: &{template:default}{{name=Disrupter Cannon Blast at @{selected|Token_Name}}} !}}} {{attack= [[1d20]]}} {{damage= [[ {0d0,3d12 - ?{Shields?}}kh1]] }} That !}}} serves no purpose unless you've got a custom API script that is looking for that for some reason, although I would highly recommend using a different command syntax if that is the case since ending curly brackets like that can mess up a wide variety of macro functions.