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

Roll Templates, Boolean Math, Auto-Calculated Fields

1517232157

Edited 1517232802
Will K.
Sheet Author
I'm putting together a character sheet for a PBTA game.  For anyone not familiar with the core mechanic of Apocalypse world games, you roll 2d6 and add a stat, a result of 6 and bellow is a failure, 7-9 is a partial success, 10+ a success.  Certain games like the one I'm making the sheet for include character advancements that allow for a great success (dynamite success in the code below) with results of 12+ under certain conditions. I have a Roll Template that displays the options a player has based on their results, but the display for 12+ is dependent on some behind the scenes Boolean Math on the character sheet that I can't get to parse when sent to the template. Here's the basics of the roll template.  This part is functioning correctly. {{#rollGreater() is_dynamite 0}} {{#rollGreater() check 11}} <div class="movedesc">{{dynamite}}</div> {{/rollGreater() check 11}} {{#rollBetween() check 10 11}} <div class="movedesc">{{success}}</div> {{/rollBetween() check 10 11}} {{/rollGreater() is_dynamite 0}} {{#^rollGreater() is_dynamite 0}} {{#rollGreater() check 9}} <div class="movedesc">{{success}}</div> {{/rollGreater() check 9}} {{/^rollGreater() is_dynamite 0}} {{#rollBetween() check 7 9}} <div class="movedesc">{{partial}}</div> {{/rollBetween() check 7 9}} {{#rollLess() check 7}} <div class="movedesc">{{miss}}</div> {{/rollLess() check 7}} The Boolean is based around the property {{is_dynamite}} which any value above 0 should unlock the 12+ results.  The math is done by following Auto-Calculated Fields: {{is_dynamite=@{move_is_dynamite}}} <input type="number" name="attr_move_is_dynamite" value="((@{logos1_active})*@{logos1_move_dynamite}) + ((@{mythos1_active})*@{mythos1_move_dynamite})" disabled> <input type="number" name="attr_logos1_active" value='[[ @{logos1_power_A_tag} + @{logos1_power_B_tag} + @{logos1_power_C_tag} + @{logos1_power_D_tag} ]]' disabled/> <input type="number" name="attr_mythos1_active" value='[[ @{mythos1_power_A_tag} + @{mythos1_power_B_tag} + @{mythos1_power_C_tag} + @{mythos1_power_D_tag} ]]' disabled/> <input type="checkbox" class="" name="logos1_power_A_tag" value="1"> ... ... <input type="checkbox" class="" name="mythos1_power_A_tag" value="1"> ... ... <input type="checkbox" class="" name="logos1_move_dynamite" value="1"> <input type="checkbox" class="" name="mythos1_move_dynamite" value="1"> Now for some reason @{move_is_dynamite} displays correctly on the sheet as a whole number, but when {{is_dynamite=@{move_is_dynamite}}} is sent tot the template, it renders it as an equation breaking the template.  Stranger still, if the first portion "((@{logos1_active})*@{logos1_move_dynamite})" would equal a non zero number the template works as intended, but if the second portion "((@{mythos1_active})*@{mythos1_move_dynamite})" gets ignored entirely.  The math is correct for what I want it to do, but roll20 doesn't seem to be doing the last part of the equation, adding "((@{logos1_active})*@{logos1_move_dynamite})" and "((@{mythos1_active})*@{mythos1_move_dynamite})" when sent to the roll template. So.... what the heck?
1517233875

Edited 1517233905
Jakob
Sheet Author
API Scripter
When you use rollGreater(), it will check the first inline roll found. In your case, that's the one in the value of logos1_active. Try {{is_dynamite=[[@{move_is_dynamite}]]}} instead to package it into one inline roll. (Though this should really be done with a sheet worker, not an autocalc field, but that's a different story).
1517255750

Edited 1517255943
Will K.
Sheet Author
Tried that, it just exports as the same equation with a couple of brackets around it.  I added {{is_dynamite}} on the template just so I could see what it's happening.  This is what it came out as:  [[(( 0 ) 1) + (( 4 ) 1)]] If you have an idea how to do it with the sheet worker script, I'm just competent enough to run a copy/paste job on anything you got. Looking to make @{move_is_dynamite} = 1 when either @{logos1_active} and @{logos1_move_dynamite} are both active, or @{mythos1_active} and @{mythos1_move_dynamite} are both active.
1517267751
GiGs
Pro
Sheet Author
API Scripter
what do you mean by "active" in this statement: "@{logos1_active} and @{logos1_move_dynamite} are both active," ?
1517268726

Edited 1517268839
Will K.
Sheet Author
Any value greater than 0.
1517269546

Edited 1517272572
GiGs
Pro
Sheet Author
API Scripter
Looking at your calc fields, something like this should work. Add this to the bottom of the html page of your character sheet. <script type="text/worker">    // first we need to tell roll20 which stats to watch for changes. on("change:logos1_power_A_tag change:logos1_power_B_tag change:logos1_power_C_tag change:logos1_power_D_tag change:mythos1_power_A_tag change:mythos1_power_B_tag change:mythos1_power_C_tag change:mythos1_power_D_tag change:logos1_move_dynamite change:mythos1_move_dynamite ", function() {     getAttrs([  // then we need to register those stats values so the script can access them. "logos1_power_A_tag", "logos1_power_B_tag", "logos1_power_C_tag", "logos1_power_D_tag", "mythos1_power_A_tag", "mythos1_power_B_tag", "mythos1_power_C_tag", "mythos1_power_D_tag", "logos1_move_dynamite","mythos1_move_dynamite"     ], function(v) { let logos1A = parseInt(v.logos1_power_A_tag) || 0;  // now we grab the values so that we can use them. let logos1B = parseInt(v.logos1_power_B_tag) || 0; // parseInt() makes sure the result is a number let logos1C = parseInt(v.logos1_power_C_tag) || 0; // the || 0 at the end basically says: if not a number, set to 0. let logos1D = parseInt(v.logos1_power_D_tag) || 0; let mythos1A = parseInt(v.mythos1_power_A_tag) || 0; // the v.[statname] part is the bit that actually gets the stat value. let mythos1B = parseInt(v.mythos1_power_B_tag) || 0; let mythos1C = parseInt(v.mythos1_power_C_tag) || 0; let mythos1D = parseInt(v.mythos1_power_D_tag) || 0; let logosDynamite = parseInt(v.logos1_move_dynamite) || 0; let mythosDynamite = parseInt(v.mythos1_move_dynamite) || 0; // the next two lines replace your logos1_active and mythos1_active stats, so if this is all they are used for, you can remove them from the sheet. let logosActive = (logos1A + logos1B + logos1C + logos1D) > 0 ? 1 : 0;  let mythosActive = (mythos1A + mythos1B + mythos1C + mythos1D) > 0 ? 1 : 0; // the expression x ? y : z says, if x = true, y; if x = false, z. // this means the above variables always equal 0 or 1. // now we replace your move_is_dynamite autocalc. let dynamite = Math.max(logosDynamite * logosActive,mythosDynamite * mythosActive); // note i used a max function, so this value is always 0 or 1. // if you need to know if both are active, change the above line to : //let dynamite = logosDynamite * logosActive + mythosDynamite * mythosActive;         setAttrs({             "move_is_dynamite": dynamite // and this saves the result to the move_is_dynamite stat.         });    }); }); </script> To use this, you'll need to change the move_is_dynamite input to: <input type="number" name="attr_move_is_dynamite" value="0" > I havent tested this, obviously, since I don't have your sheet code. But it looks right.
Awesome!  Cant wait to get back to my computer and try this out.  Also, wow, thanks for making that so easy to follow.  I'll let ya know how it turns out.
It works!  Thanks GG!  I'll make sure to credit ya in there somewhere! Thanks to Jackobs too, I had to add the brackets as you suggested to make the sheetworker and template get along, and I think the reason it didn't work for the auto-calc fields was that there were nested inline rolls involved.  I don't think roll20 likes that
1517303607
GiGs
Pro
Sheet Author
API Scripter
That's great, Will. Glad I could help.