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

Can a Roll Template property be converted to an empty string if it contains a zero value? (Or something that has that effect)

June 02 (4 years ago)
Evil Hat Productions
Pro
Marketplace Creator
Sheet Author
Compendium Curator

Near as I can tell, the answer is "no", but let me give a reductive example of what I'm trying.

<input type="checkbox" name="attr_MyAtt" value="MyAtt is set.">
<button class="sheet-broadcast-button" type="roll" name="roll_Show" value="&{template:my-template} {{text=@{MyAtt}}}"></button>
<rolltemplate class="sheet-rolltemplate-my-template">
{{#text}}
</rolltemplate>

So right now if the checkbox in the above example is checked, then the output is:

MyAtt is set.

And if the checkbox is not checked, then the output is:

0

Zero! Not an empty string! If it was an empty string this wouldn't be a problem. Since Roll20 apparently decides that an unchecked checkbox property if evaluated is zero (I get it; math often gets done with these things, but in my case I'm dealing with text, so I need it to transmit an empty string rather than a zero).

Because Roll20 sets an explicit value for an explicitly un-checked attribute... I'm kinda stuck here. Is there some ninja codetrick I'm missing that will let you test whether an @{MyAtt} evaluates to zero, and make it instead get treated as an empty string?

June 02 (4 years ago)
Kraynic
Pro
Sheet Author

I'm not sure if you can do that with a checkbox.  Have you thought about doing radio buttons instead?  You could have 2 radio buttons linked to that attribute.  One would have the blank value (value=""), and the other would have the "MyAtt is set" value.

June 02 (4 years ago)
Evil Hat Productions
Pro
Marketplace Creator
Sheet Author
Compendium Curator

Radio buttons won't work for the specifics of my situation, I'm afraid. More than anything, I'm more interested in the answer to: If a property comes across as set to zero, how can I put logic into the roll template — either internal to the template itself, or at the time I'm feeding it through to the template in the <button> call — that notices the value is zero and skips it or otherwise treats it as a null?

In other words, I need an answer that makes the assumption that it has to be a checkbox as the starting point.

June 02 (4 years ago)

Edited June 02 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter


Evil Hat Productions said:

Because Roll20 sets an explicit value for an explicitly un-checked attribute... I'm kinda stuck here. Is there some ninja codetrick I'm missing that will let you test whether an @{MyAtt} evaluates to zero, and make it instead get treated as an empty string?

Is "My Att is set." purely for testing, or will it be the actual value you want to use? Knowing the answer to that can change the answer. 

But if you changed your rolltemplate string to include an inline roll you can check for the value in the rolltemplate, and only print it if its not zero.

&{template:my-template} {{text=[[@{MyAtt}]]}}

Then check for a value that is NOT 0.

<rolltemplate class="sheet-rolltemplate-my-template">
{{#^rollTotal() text 0}}{{#text}}{{/^rollTotal() text 0}}
</rolltemplate>


For cases like this it would be much better to have your checkbox give a numeric value, then in the roll template you can have something happen when it is ON (value = 1).

<input type="checkbox" name="attr_MyAtt" value="1">
<button class="sheet-broadcast-button" type="roll" name="roll_Show" value="&{template:my-template} {{text=[[@{MyAtt}]]}}"></button>
<rolltemplate class="sheet-rolltemplate-my-template">

{{#rollTotal() text 1}}My Att is set.{{/rollTotal() text 1}}

</rolltemplate>




June 02 (4 years ago)

Edited June 02 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

As an addendum, a lot of sheets use this kind of approach. If it's necessary to have the text "My Att is set." outside the rolltemplate, you'd use a second attribute containing the text. 

<input type="checkbox" name="attr_MyAtt_check" value="1">

<input type="text" name="attr_MyAtt_text" value="">

<button class="sheet-broadcast-button" type="roll" name="roll_Show" value="&{template:my-template} {{text=[[@{MyAtt_check}]]}}"></button>
<rolltemplate class="sheet-rolltemplate-my-template">

{{#rollTotal() text 1}}{{#MyAtt_text}}{{/rollTotal() text 1}}

</rolltemplate>

You might use a sheet worker to check changes to the MyAtt_check value and fill in the MyAtt_text value appropriately, or it might be set manually be players, or it might be fixed. Whatever the case, you also have a numerical toggle that has a value of 1 or 0, to decide what happens in the rolltemplate.

June 02 (4 years ago)
Evil Hat Productions
Pro
Marketplace Creator
Sheet Author
Compendium Curator

Since it was asked: The toggle value is, preferrably, a string containing the data-i18n value of the text the checkbox is associated with. So my "real world" case is I want non-empty text when the checkbox is checked, and an empty string when it's not. The roll idea is an interesting one, I'll see if I can get that to not-barf.    

June 02 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

I'm not sure what would happen to text, especially data-i18n text, inside inline roll brackets sent to a rolltemplate. I've never done that but it might work! If not, the more robust solution is the method in my second post.

June 02 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

PS: I just noticed I forgot the () on the rollTotal calls - rollTotal should be rollTotal().

I'm always doing that in my own sheets, too (sigh). I've edited the above posts.

June 02 (4 years ago)
Evil Hat Productions
Pro
Marketplace Creator
Sheet Author
Compendium Curator

Hm, trying the roll thing just resulted in a syntax error. 

SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "%u2022" found.

I'll angle instead for hard-coding a custom roll template specific for each instance where I need this behavior, with 0/1 values for the checkbox, as the template/button/macro syntax isn't sophisticated enough to handle this kind of conditional. Thanks for the suggestions!