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

Show/hide attributes using checkbox and roll templates?

May 24 (10 years ago)
vÍnce
Pro
Sheet Author
I'm trying to use checkboxes on the sheet to show/hide attributes to be included in the output of a macro using roll template logic. I'm very close to getting what I want. The attributes are shown correctly when checked, but I'm having a problem hiding the attribute when unchecked. The attribute defaults to value="0" when unchecked so my macro displays "0" instead of just hiding the attribute.
I'm probably going about this all wrong.
Any suggestions appreciated. TIA

With boxes checked,


Notes are included (yea!)



This is my problem.

With boxes unchecked,



The default value="0" for unchecked is being displayed (boo!) I want nothing to show if the box is unchecked.



Here's a snippet of my html
<div>
<span><input type="hidden" title="@{repeating_weapon_X_show-melee-notes}" name="attr_show-melee-notes" value="{{@{repeating_weapon_X_show-melee-attack-notes}}}"/></span>

<span><input type="hidden" title="@{repeating_weapon_X_show-ranged-notes}" name="attr_show-ranged-notes" value="{{@{repeating_weapon_X_show-ranged-attack-notes}}}"/></span>

<span><input type="hidden" title="@{repeating_weapon_X_show-cmb-notes}" name="attr_show-cmb-notes" value="{{@{repeating_weapon_X_show-melee-cmb-notes}}}"/></span>

<span><input type="hidden" title="@{repeating_weapon_X_show-attack-notes}" name="attr_show-attack-notes" value="{{@{repeating_weapon_X_show-attack-notes}}}"/></span>
</div>


<div class="sheet-table">
<div class="sheet-table-row">

<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><b title="Include these additional notes with the attack roll.">Include notes?</b></span>

<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" title="@{repeating_weapon_X_show-melee-attack-notes}" name="attr_show-melee-attack-notes" value="@{melee-attack-notes}"/><b title="Include Melee attack notes"> Melee Notes</b></label></span>

<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" title="@{repeating_weapon_X_show-ranged-attack-notes}" name="attr_show-ranged-attack-notes" value="@{ranged-attack-notes}"/><b title="Include Ranged attack notes"> Ranged Notes</b></label></span>

<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" title="@{repeating_weapon_X_show-cmb-notes}" name="attr_show-cmb-notes" value="@{cmb-notes}"/><b title="Include CMB notes"> CMB Notes</b></label></span>

<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" title="@{repeating_weapon_X_show-attack-notes}" name="attr_show-attack-notes" value="@{attack-notes}"/><b title="Include Attack notes"> Attack Notes</b></label></span>
</div>
</div>

roll template(just included the snippet that pertains to the code above.)
{{#show_melee_notes}}
<tr><td colspan="2">Melee Notes: <span style="font-weight:normal;">{{show_melee_notes}}</span></td></tr>
{{/show_melee_notes}}
{{#show_ranged_notes}}
<tr><td colspan="2">Ranged Notes: <span style="font-weight:normal;">{{show_ranged_notes}}</span></td></tr>
{{/show_ranged_notes}}
{{#show_cmb_notes}}
<tr><td colspan="2">CMB Notes: <span style="font-weight:normal;">{{show_cmb_notes}}</span></td></tr>
{{/show_cmb_notes}}
{{#show_attack_notes}}
<tr><td colspan="2">Attack Notes: <span style="font-weight:normal;">{{show_attack_notes}}</span></td></tr>
{{/show_attack_notes}}

{{#allprops()
character_name character_id name_link attack damage crit_confirm crit_damage description attack2 damage2 crit_confirm2 crit_damage2 show_melee_notes show_ranged_notes show_cmb_notes show_attack_notes}}
<tr><td>{{key}}</td><td>{{value}}</td></tr>
{{/allprops() 
character_name character_id name_link attack damage crit_confirm crit_damage description attack2 damage2 crit_confirm2 crit_damage2 show_melee_notes show_ranged_notes show_cmb_notes show_attack_notes}}
Macro
{template:pf_attack}{{show_melee_notes=@{show-melee-attack-notes}}} {{show_ranged_notes=@{show-ranged-attack-notes}}} {{show_cmb_notes=@{show-cmb-notes}}} {{show_attack_notes=@{show-attack-notes}}} 
May 24 (10 years ago)

Edited May 24 (10 years ago)
Coal Powered Puppet
Pro
Sheet Author
I switched from using a check box to using two radio buttons (styled to look like a check box). One button had the value to show, and the other had a value of " ".

Edit: My button looks like this:


And the result looks like this (yes, stole the hook things; shameless copying is the sincerest form of flattery and all):
May 24 (10 years ago)

Edited May 24 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
Vince, take a look at my 5e shaped sheet. I do this for weapons, spells, actions, etc.

I'll copy + paste the Melee Weapons code for ease of seeing:

<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_emote" value="{{emote=@{repeating_weapons_melee_{{num}}_emote}}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_attack" value="{{attack=[[d20cs>@{repeating_weapons_melee_{{num}}_crit_range} + @{repeating_weapons_melee_{{num}}_to_hit} + (@{global_weapon_attack_bonus}) + (@{global_melee_attack_bonus})]]}} {{attackadv=[[d20cs>@{repeating_weapons_melee_{{num}}_crit_range} + @{repeating_weapons_melee_{{num}}_to_hit} + (@{global_weapon_attack_bonus}) + (@{global_melee_attack_bonus})]]}} {{targetAC=@{attacks_vs_target_ac}}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_reach" value="{{reach=@{repeating_weapons_melee_{{num}}_reach}}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_damage" value="{{action_damage=[[@{repeating_weapons_melee_{{num}}_dmg} + @{repeating_weapons_melee_{{num}}_dmg_total} + (@{global_weapon_damage_bonus}) + (@{global_melee_damage_bonus}) + 0d0]]}} {{action_damage_type=@{repeating_weapons_melee_{{num}}_dmg_type}}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_second_damage" value="{{action_second_damage=[[@{repeating_weapons_melee_{{num}}_second_dmg} + (@{global_weapon_damage_bonus}) + (@{global_melee_damage_bonus}) + 0d0]]}} {{action_second_damage_type=@{repeating_weapons_melee_{{num}}_second_dmg_type}}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_crit" value="{{can_crit=1}} {{action_crit_damage=[[@{repeating_weapons_melee_{{num}}_dmg} + @{repeating_weapons_melee_{{num}}_bonus_crit_dmg} + 0d0]]}} {{action_crit_damage_adv=[[@{repeating_weapons_melee_{{num}}_dmg} + @{repeating_weapons_melee_{{num}}_bonus_crit_dmg} + 0d0]]}} {{action_second_crit_damage=[[@{repeating_weapons_melee_{{num}}_second_dmg} + 0d0]]}} {{action_second_crit_damage_adv=[[@{repeating_weapons_melee_{{num}}_second_dmg} + 0d0]]}}">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_bonuses" value="1">
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_var_crit_bonus" value="1">

<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_emote" class="sheet-tab-action sheet-toggle-emote" value="@{repeating_weapons_melee_{{num}}_var_emote}"><span class="sheet-tab-action sheet-toggle-emote">Emote</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_attack" class="sheet-tab-action sheet-toggle-attack" value="@{repeating_weapons_melee_{{num}}_var_attack}"><span class="sheet-tab-action sheet-toggle-attack">Attack</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_reach" class="sheet-tab-action sheet-toggle-reach" value="@{repeating_weapons_melee_{{num}}_var_reach}"><span class="sheet-tab-action sheet-toggle-reach">Reach</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_damage" class="sheet-tab-action sheet-toggle-damage" value="@{repeating_weapons_melee_{{num}}_var_damage}"><span class="sheet-tab-action sheet-toggle-damage">Dmg</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_second_damage" class="sheet-tab-action sheet-toggle-second-damage sheet-mar-t-md" value="@{repeating_weapons_melee_{{num}}_var_second_damage}"><span class="sheet-tab-action sheet-toggle-second-damage sheet-mar-t-md">Secondary</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_crit" class="sheet-tab-action sheet-toggle-crit sheet-mar-t-md" value="@{repeating_weapons_melee_{{num}}_var_crit}"><span class="sheet-tab-action sheet-toggle-crit sheet-mar-t-md">Crit</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_crit_bonus" class="sheet-tab-action sheet-toggle-crit-bonus sheet-mar-t-nine" value="@{repeating_weapons_melee_{{num}}_var_crit_bonus}"><span class="sheet-tab-action sheet-toggle-crit-bonus sheet-mar-t-nine">Bonus</span>
<input type="checkbox" name="attr_repeating_weapons_melee_{{num}}_toggle_bonuses" class="sheet-tab-action sheet-toggle-bonuses" value="@{repeating_weapons_melee_{{num}}_var_bonuses}"><span class="sheet-tab-action sheet-toggle-bonuses">Bonuses</span>

<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_macro_options" value="@{repeating_weapons_melee_{{num}}_toggle_emote} @{repeating_weapons_melee_{{num}}_toggle_attack} @{repeating_weapons_melee_{{num}}_toggle_crit} @{repeating_weapons_melee_{{num}}_toggle_reach} @{repeating_weapons_melee_{{num}}_toggle_damage} @{repeating_weapons_melee_{{num}}_toggle_second_damage}">




<button type="roll" class="sheet-roll" name="roll_repeating_weapons_melee_{{num}}_weapon" value="@{output_option} &{template:5eDefault} {{attack_roll=1}} {{character_name=@{character_name}}} @{show_character_name} {{title=@{repeating_weapons_melee_{{num}}_name}}} {{melee=1}} @{repeating_weapons_melee_{{num}}_macro_options}">
  <span>Melee</span>
</button>
{{num}} is parsed to 0-7 via gulp - this is just the code view. The fields themselves aren't relevant so I didn't include them, but they are either type number or text.

I see you have used hidden fields as well - that's good. For any other devs that read this - it is immensely helpful for making future changes. If you put the code inside the checkbox then it will save that value to the user's sheet and you can never make adjustments to formulas without causing breaking changes. This is paramount for allowing future development.

The most important part up there is the macro_options. That will solve your "0" issue.

Let me know if anything is confusing.
May 24 (10 years ago)
vÍnce
Pro
Sheet Author
THANK YOU both. I started to get "code-fused" and had to ask for some help. :-P

May 24 (10 years ago)
Coal Powered Puppet
Pro
Sheet Author

Vince said:

THANK YOU both. I started to get "code-fused" and had to ask for some help. :-P


A drop in the bucket to the help you and others have given me, but you are very welcome.
May 25 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
Did you figure it out? I saw your post by email, but you've since deleted it.

This is macro options before
<input type="hidden" name="attr_repeating_weapons_melee_{{num}}_macro_options" value="@{repeating_weapons_melee_{{num}}_toggle_emote} @{repeating_weapons_melee_{{num}}_toggle_attack} @{repeating_weapons_melee_{{num}}_toggle_crit} @{repeating_weapons_melee_{{num}}_toggle_reach} @{repeating_weapons_melee_{{num}}_toggle_damage} @{repeating_weapons_melee_{{num}}_toggle_second_damage}">
After it will become lots of 0s if they are not filled in.

This button
<button type="roll" class="sheet-roll" name="roll_repeating_weapons_melee_{{num}}_weapon" value="@{output_option} &{template:5eDefault} {{attack_roll=1}} {{character_name=@{character_name}}} @{show_character_name} {{title=@{repeating_weapons_melee_{{num}}_name}}} {{melee=1}} @{repeating_weapons_melee_{{num}}_macro_options}">
  <span>Melee</span>
</button>
Would then become
<button type="roll" class="sheet-roll" name="roll_repeating_weapons_melee_{{num}}_weapon" value="@{output_option} &{template:5eDefault} {{attack_roll=1}} {{character_name=@{character_name}}} @{show_character_name} {{title=@{repeating_weapons_melee_{{num}}_name}}} {{melee=1}} 0 0 0 0 0 0 0">
  <span>Melee</span>
</button>
And the 0s would have no effect.
May 25 (10 years ago)
vÍnce
Pro
Sheet Author
Thanks Mark for the extra bit of info. First, for some reason, I had to rename my name=, and value= attributes to not included the "repeatable_weapon_X_..." It just wouldn't function until I did that. I kept it in the title= tags for the checkboxes though.

I had left @{macro_options}, which would finally display the attributes being toggled, inside {{ }}... that was a mistake as well, as you have so graciously pointed out. :-) By leaving it within {{ }} my template would post the "0 0 0 0" like it's supposed to. Once I pulled @{macro_options} out of the double curlies, presto, everything works.

Again, a BIG thank you for the help.
May 25 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
Glad it all worked out.

If you ever needs quicker responses on sheet info I can give you my personal info as well. Just let me know. :)
May 25 (10 years ago)
vÍnce
Pro
Sheet Author
Cheers
May 25 (10 years ago)
vÍnce
Pro
Sheet Author
Spoke too soon.
This may be a limitation of repeating items...
My checkboxes work great within the repeating item. I can toggle which notes(attributes located outside of the repeating item) are hidden/shown via roll template when using the repeating item button roll. However,

PROBLEM:
the PF sheet uses a button bar in conjunction with repeating items. The button bar is a row of 27(0-26) "hard coded" button rolls that link directly to the first 27 repeating items and their individual attributes.

I can't seem to include the @{macro_options} into the button bar macros. "No attribute found" error. I have tried @{repeating_weapon_0_macro_options} as well.

I know that in order to use a repeating item's, auto-calculated attribute within the button bar macro, you have to insert the entire formula in order for it to work. Not sure "which" part of our checkbox function I should use to get it to hide/show the toggled notes. A quick test seemed that it would only display the value of the attribute before it in the chain(usually another attribute), thus it doesn't seem possible for this to work from outside the repeating item.

Suggestions?
Thanks

current code that hide/show attribute output (works when used from a sheet roll inside the repeating item)

<input type="hidden" name="attr_var_melee_notes" value="{{melee_notes=@{melee-attack-notes}}}"/>
<input type="hidden" name="attr_var_ranged_notes" value="{{ranged_notes=@{ranged-attack-notes}}}"/>
<input type="hidden" name="attr_var_CMB_notes" value="{{CMB_notes=@{CMB-notes}}}"/>
<input type="hidden" name="attr_var_attack_notes" value="{{attack_notes=@{attack-notes}}}"/>
<div class="sheet-table">
<div class="sheet-table-row">
<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><b title="Include these additional notes with the attack roll.">Include notes?</b></span>
<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" name="attr_toggle_melee_notes" value="@{var_melee_notes}" title="@{repeating_weapon_X_toggle_melee_notes}"/><b title="Include Melee attack notes"> Melee Notes</b></label></span>
<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" name="attr_toggle_ranged_notes" value="@{var_ranged_notes}" title="@{repeating_weapon_X_toggle_ranged_notes}"/><b title="Include Ranged attack notes"> Ranged Notes</b></label></span>
<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" name="attr_toggle_CMB_notes" value="@{var_CMB_notes}" title="@{repeating_weapon_X_toggle_CMB_notes}"/><b title="Include CMB notes"> CMB Notes</b></label></span>
<span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><label><input type="checkbox" name="attr_toggle_attack_notes" value="@{var_attack_notes}" title="@{repeating_weapon_X_toggle_attack_notes}"/><b title="Include Attack notes"> Attack Notes</b></label></span>
</div>
</div>
<input type="hidden" name="attr_macro_options" value="@{toggle_melee_notes} @{toggle_ranged_notes} @{toggle_CMB_notes} @{toggle_attack_notes}"/>

<b>Macro Text        </b>
<input type="checkbox" class="sheet-macro-text-show" title="@{repeating_weapon_X_macro-text-show}" name="attr_macro-text-show" value="1" style="opacity:0;width: 35px;height: 16px;position: relative;top: 5px;left: 6px;margin: -32px;cursor: pointer;z-index: 1;"/><span></span>
<textarea class="sheet-macro-text" title="@{repeating_weapon_X_macro-text}" name="attr_macro-text">&{template:pf_attack} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{name=@{name}}} {{attack=[[1d20cs>[[@{crit-target}]] + [[@{total-attack}]]]]}} {{damage=[[@{damage-dice-num}d@{damage-die} + [[@{total-damage}]]]]}} {{crit_confirm=[[1d20 + [[@{total-attack}]] ]]}} {{crit_damage=[[[[(@{damage-dice-num} * (@{crit-multiplier} - 1))]]d@{damage-die} + [[(@{total-damage} * (@{crit-multiplier} - 1))]] ]]}} {{type=@{type}}} {{description=@{notes}}} @{macro_options}</textarea>

button bar example (sheet roll from outside the repeating item)

<span class="sheet-table-data sheet-center"><button type="roll" name="roll_repeating_weapon_0_Attack" title="%{selected|repeating_weapon_0_Attack}" value="&{template:pf_attack} {{character_name=@{character_name}}} {{character_id=@{character_id}}} {{name=@{repeating_weapon_0_name}}} {{attack=[[1d20cs>@{repeating_weapon_0_crit-target} + [[(@{repeating_weapon_0_proficiency} + (((@{repeating_weapon_0_enhance} + @{repeating_weapon_0_masterwork}) + abs(@{repeating_weapon_0_enhance} - @{repeating_weapon_0_masterwork})) / 2) + @{repeating_weapon_0_attack} + @{repeating_weapon_0_attack-type} + @{armor-proficiency})]] ]]}} {{damage=[[@{repeating_weapon_0_damage-dice-num}d@{repeating_weapon_0_damage-die} + [[(@{repeating_weapon_0_enhance} + @{repeating_weapon_0_damage} + @{repeating_weapon_0_damage-ability})]] ]]}} {{crit_confirm=[[1d20 + [[(@{repeating_weapon_0_proficiency} + (((@{repeating_weapon_0_enhance} + @{repeating_weapon_0_masterwork}) + abs(@{repeating_weapon_0_enhance} - @{repeating_weapon_0_masterwork})) / 2) + @{repeating_weapon_0_attack} + @{repeating_weapon_0_attack-type} + @{armor-proficiency})]] ]]}} {{crit_damage=[[[[([[@{repeating_weapon_0_damage-dice-num}]] * ([[@{repeating_weapon_0_crit-multiplier}]] - 1))]]d@{repeating_weapon_0_damage-die} + [[([[(@{repeating_weapon_0_enhance} + @{repeating_weapon_0_damage} + @{repeating_weapon_0_damage-ability})]] * (@{repeating_weapon_0_crit-multiplier} - 1))]] ]]}} {{type=@{repeating_weapon_0_type}}} {{description=@{repeating_weapon_0_notes}}}"></button></span>

May 25 (10 years ago)

Edited May 25 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
Yup. You're screwed.
I was inspired by your hard coded buttons that makes repeatable items accessible outside of the repeating area. It doesn't work. I spent hours fiddling with it. If you read the suggestion in this topic you'll see the problem: repeating attributes do not have defaults and hence the errors.

This is why I use pseudo repeating items (Hard code the amount shown, but still use the repeating name so they don't appear in the attributes list).

Sorry. :(
May 26 (10 years ago)
vÍnce
Pro
Sheet Author
I knew it.

Maybe I can also add 4 rows of checkboxes under the 27 buttons(108 checkboxes!) to toggle notes from outside repeating items so that people that use drag/drop and/or reference the attack button roll from an ability macro can have the option to toggle notes as well. Yeah, right.

Damn you repeating item limitations.

Thanks again Mark.
May 26 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
You would have to duplicate everything really, unless you accept some errors in case everything isn't filled in (even ones that have value="0"). I saw those kind of errors on the PF sheet.

If you have to duplicate everything there really isn't much reason to do repeating imo.
May 26 (10 years ago)
vÍnce
Pro
Sheet Author
I decided to just include two options, use the toggles within the repeating item for that repeating item, and/or a global toggle that works from outside the repeating item but applies to the entire button bar. It's not the outcome I was hoping for, but still an improvement worth doing. Thanks Mark