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

Need help with hiding rolls results if the value is empty

1674796527

Edited 1674796717
라브
Pro
Translator
Hello,  I am working on a custom character sheet and wish to hide the roll result if there were no modifiers entered in the input field.  The button html is currently like this: <div class="example">     <input type="number" name="attr_modifier" value="" /> </div> <div class="dice-button">     <button type="roll" class="sheet-dice-icon" value="&{template:custom} {{name=@{character_name}}} {{r1=[[1d20+@{modifier}]]}} {{desc=@{desc}}}"></button> </div> And the roll template looks like this: <rolltemplate class="sheet-rolltemplate-custom">   ...         {{#dice}}         <div class="result-style">{{r1}}</div>     {{/dice}} </rolltemplate> Currently, even if the modifier attribute is empty, it still rolls 1d20 and displays the result because of how I structured {{r1}}. Would there be a better way to structure this? Or is there a JS to display div as none when the value is empty? Thanks in advance. 
1674799342
GiGs
Pro
Sheet Author
API Scripter
The trick here is using Logic Helpers in Rolltemplates. You will need to do two things. First, add an inline roll that only contains your modifier, like this: value="&{template:custom} {{name=@{character_name}}} {{modifier=[[@{modifier}]]}} {{r1=[[1d20+@{modifier}]]}} {{desc=@{desc}}} Then if you want to show the roll when modifier is not = 0, you need to modify our rolltemplate: {{#dice}} {{#^rollTotal modifier 0}}<div class="result-style">{{r1}}</div>{{/^rollTotal modifier 0}}     {{/dice}} The ^ before rollTotal means NOT, so this is when modifier does not equal 0.
1674801894
라브
Pro
Translator
GiGs said: The trick here is using Logic Helpers in Rolltemplates. You will need to do two things. First, add an inline roll that only contains your modifier, like this: value="&{template:custom} {{name=@{character_name}}} {{modifier=[[@{modifier}]]}} {{r1=[[1d20+@{modifier}]]}} {{desc=@{desc}}} Then if you want to show the roll when modifier is not = 0, you need to modify our rolltemplate: {{#dice}} {{#^rollTotal modifier 0}}<div class="result-style">{{r1}}</div>{{/^rollTotal modifier 0}}     {{/dice}} The ^ before rollTotal means NOT, so this is when modifier does not equal 0. Thank you so much, GiGs! I really appreciate your help!