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

Display Roll Query only if an attribute is set

Is it possible to selectively display a roll query in a macro based on whether or not another attribute is set? I'm able to selectively add the result based on another attribute, but I'd prefer to just not have the query show if the option attribute is set. This is what I currently have: {{Dodge=[[d20+@{dodge} - ?{Dodging gunfire?| > 50',0| 10'-50',5| < 10',10 } * @{opt_dodge_penalty},0dl1 ]]}} `opt_dodge_penalty` is a checkbox that's either 0 or 1. If it's one, the roll query should be taken into account. If it's 0, it shouldn't. But I'd like to put that in front of the roll query somehow to determine whether or not to display the query altogether.
1631163380

Edited 1631163558
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can do this a few ways but they all involve sheetworkers. You can assemble the roll with a sheetworker. Something like: on('change:opt_dodge_penalty',(event)=>{ getAttrs(['opt_dodge_penalty'],(attributes)=>{ const setObj = {}; if(+attributes.opt_dodge_penalty===1){ setObj.dodge_query = `- ?{Dodging gunfire?|> 50',0|10'-50',5|< 10',10 }`; }else{ setObj.dodge_query = '' } }); }); This would require that you create an attribute to store the query in and reference it in the macro like so: {{Dodge=[[d20+@{dodge} - @{dodge_query}]]}} Note, I also took out the ,0d11 , as it didn't seem to have a purpose here. You could also use the new roll parsing capability and build the roll each time the action button is clicked. For this You'll need to change your roll button to an action button. Something like: <button type='action' name='act_dodge_roll'> And then the sheetworker looks like: on('clicked:dodge_roll',(event)=>{ getAttrs(['opt_dodge_penalty'],async (attributes)=>{ let roll = '&{template:your-template} {{fields=that you need}} {{Dodge=[[d20+@{dodge}';//Assemble our basic roll if(+attributes.opt_dodge_penalty===1){ message += `- ?{Dodging gunfire?|> 50',0|10'-50',5|< 10',10 }]]}}`;//add the query if needed }else{ setObj.dodge_query += ']]}}'//otherwise, just close the inline roll and roll template field } let roll = await startRoll(message);//send the roll, wait for the results of the roll finishRoll(roll.rollId);//Once the results of the roll come back, tell the roll to submit to chat since we aren't doing any parsing of the roll results. }); }); Edit: And actually, if you don't need opt_dodge_penalty to be a 0 or 1, then you could do this without sheetworkers as well by making the query the checked value of opt_dodge_penalty: <input type='checkbox' name='attr_opt_dodge_penalty' value='?{Dodging gunfire?|> 50',0|10'-50',5|< 10',10 }'> And then reference it like: {{Dodge=[[d20+@{dodge} - @{opt_dodge_penalty}]]}} but I'm assuming that you need it to be 0 or 1 for other reasons.
1631220652

Edited 1631223208
Grinning Gecko
Pro
Sheet Author
I love your last solution as it's very elegant, but it doesn't seem to work for having a related option in the sheet.json. { "attribute": "opt_dodge_penalty", "displayname": "Apply Rifts: Ultimate Edition penalties to dodging gunfire", "description": "In Rifts: Ultimate Edition, characters are -10 to dodge gunfire at less than 10 feet, and -5 between 10 and 50 feet.", "type": "checkbox", "value": "?{Dodging gunfire?|> 50',0|10'-50',5|< 10',10}", "checked": "checked" }, <input type="checkbox" name="attr_opt_dodge_penalty" value="?{Dodging gunfire?|> 50',0|10'-50',5|< 10',10}" /> Even if the option is checked in the game settings, it's never checked on a new character sheet. Any idea how to connect the two without changing the value to "1"? Do I need to use HTML entities somewhere? UPDATE : Looks like it was the first single quote that was throwing it off. I changed those to the word "feet" in both entries and all is good :)
1631225126
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
glad it worked for you!
1634708527

Edited 1634710805
Sorry to hijack/necro this but I imagine this is something very simple that I'm just not wrapping my head around. I am looking to effectively just do this: Scott C. said: This would require that you create an attribute to store the query in and reference it in the macro like so: {{Dodge=[[d20+@{dodge} - @{dodge_query}]]}} I want to create an attribute to store the value of a query from a longer calculation/macro.  I've only used a bit of API and haven't got a firm grasp of the roll20 wizardry. <div class="sheet-item sheet-redbgns" style="width: 15%;"><button name="roll_PsyHit" type="roll" value="!roll40k @{character_name}, ?{Focus Power Characteristic | Willpower,@{Willpower} | Perception,@{Perception} | Psyniscience,@{PsyniscienceCharacteristic}}, [[(@{PsyRating} - ?{Psy Use?|1}) *10 + ?{Modifier|0}]]"> <span data-i18n="hit-u">Hit</span> </button></div> This is the button for the roll and I want to save the used PsyRating into an attribute so that when I perform the damage roll that can be added if necessary, also to add some flavor text in the result of the roll. EDIT: I guess I should add that I'm editing/fixing an existing sheet and am trying to go for the least impact possible.  I might have to completely rewrite the existing API if there's not a way to pull out this singular query and store it in an attribute.
1634711782

Edited 1634711835
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Since you are creating (editing) a sheet, you've actually got more options Dustin and don't need the API for what you want to do. The recently released roll parsing update to sheetworkers will allow you to do all those calculations directly in the sheet in response to the roll being made. Read up on the roll parsing info and then post a new thread in the custom sheets forum with any questions. We'll be happy to help you there.