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

Help adjusting stacking advantage

1602499954

Edited 1602499964
Pete
Pro
Marketplace Creator
Sheet Author
My custom sheet for my playtest has stacking advantage. My issue is there are certain rolls that I'd like to have start with either 1 advantage or 1 disadvantage. Like D&D 5e, they cancel each other out, so I think I'd need to have a custom variable for these, but I'm not sure how to pull it off. Currently the button, looks like this with you select advantage/disadvantage and the number of them. You use 0 for neither advantage or disadvantage. <span> <input type="radio" class="toggle-center" name="attr_advantagetoggle" checked="checked" value="adv"><span >ADVANTAGE</span> <input type="text" class="num_values advDisAdvDice" value="0" name="attr_advDisAdvDice"> <input type="radio" class="toggle-right" name="attr_advantagetoggle" value="disadv"><span >DISADVANTAGE</span> </span> My rolls all look a bit like this, using two variables, advantage dice ("adDice") to determine how many additional dice to roll and keep lowest/highest ("klkh") to determine advantage or disadvantage. {{roll=[[(@{wpnDice}@{adDice})d6@{klkh}@{wpnDice}+@{wpnBonus}]]}} The info that sets this looks like this: on("change:advantagetoggle change:advDisAdvDice", function() { getAttrs(["advantagetoggle","advDisAdvDice"], function(values) { console.log("xxx: "+values.advantagetoggle); let toggle = values.advantagetoggle; let dice=" "; let klkh=" "; if (toggle=="adv"){ dice="+"+values.advDisAdvDice; klkh="kh"; } else if (toggle=="disadv") { dice="+"+values.advDisAdvDice; klkh="kl"; } console.log("dice: "+dice); console.log("klkh: "+klkh); setAttrs({adDice:dice,klkh:klkh}); }); }); My question is if anyone can help me establish a way to set rolls that start with either 1 advantage or disadvantage. For instance a roll with 1 disadvantage would have -1 advantage when advantage > 0, switch to disadvantage and add 1 when at 0, or +1 when already on disadvantage. Any assistance is greatly appreciated. I'm thinking there might be a simpler way to do this whole process. Maybe a pop up dialogue box instead of a toggle for the whole sheet? Maybe using negative numbers as disadvantage instead of the toggle?
1602525986
GiGs
Pro
Sheet Author
API Scripter
I'm not following your description of the problem. Can you describe how this dice system works, if we were sitting at your gaming table, and you had to explain it to a new player. Dont refer to roll20 at all.
1602529151

Edited 1602585580
Pete
Pro
Marketplace Creator
Sheet Author
Whenever you have advantage on a roll, you roll an additional die and disregard the lowest die rolled. This effect stacks, rolling additional dice and disregarding the same amount. Disadvantage is the opposite. You roll an additional die and disregard the highest die rolled. If a roll would have both advantage and disadvantage, they cancel each other out, 1 for 1. Two advantage and One disadvantage is simplified to one advantage. EDIT: What I'm trying to create is a way of having roll that have 1 built in advantage or disadvantage. The challenge is since they cancel each other out, there needs to be a multiple if else or some other equation to account for the various possibilities.
1602706837

Edited 1602706971
Pete
Pro
Marketplace Creator
Sheet Author
So my attempts at fixing this myself have proved unsuccessful. Perhaps someone could critique my sheetworker attempt. I added the following below my regular advantage sheetworker that I posted above. on("change:advantagetoggle change:advDisAdvDice", function() { getAttrs(["advantagetoggle","advDisAdvDice"], function(values) { console.log("xxx: "+values.advantagetoggle); let toggle = values.advantagetoggle; let dice=" "; let klkh=" "; if (toggle=="adv"){ dice="+"+values.advDisAdvDice; klkh="kh"; } else if (toggle=="disadv") { dice="+"+values.advDisAdvDice; klkh="kl"; } console.log("dice: "+dice); console.log("klkh: "+klkh); setAttrs({adDice:dice,klkh:klkh}); }); }); on("change:advantagetoggle change:advdisadvdice", function() { getAttrs(["advantagetoggle","advdisadvdice"], function(values) { console.log("dxxx: "+values.advantagetoggle); let advdice= parseInt(values.advdisadvdice) let toggle = values.advantagetoggle; let disaddice=" "; let disklkh=" ";      if (advdice=="0") { let disaddice=(1); disklkh="kl"; } else if (toggle=="adv" && advdice > 0){ let disaddice=(values.advdisadvdice-1); disklkh="kh"; }                     else {                     let disaddice = (values.advdisadvdice+1)                      } console.log("dice: "+disaddice); console.log("klkh: "+disklkh); setAttrs({disaddice:disaddice,disklkh:disklkh}); }); }); So far the regular advantage/disadvantage one works (the top half), but my attempt at creating a version that starts with one disadvantage seems to fail to generate any value. 
1602707409
GiGs
Pro
Sheet Author
API Scripter
Do you have both those sheet workers installed at the same time? If so, that is likely your issue. Since they use the on(change) events, and the same getAttrs, you should combine them into a single worker. Also, your casing is inconsistent. In the first one you have some upper case letters, and in the second one its all lower case. You should use all lower case in the code on the change event lines, regardless of whatever the name in the html is.
1602707691

Edited 1602707774
GiGs
Pro
Sheet Author
API Scripter
Here's the main problem with your second worker:                                         if (advdice=="0") { let disaddice=(1); disklkh="kl"; } You need to remove the let from those statements:                                         if (advdice=="0") { disaddice= 1; disklkh="kl"; } When you use let inside a code block, like those if statements, it creates a variable that only exists in that code block . You have already declared disaddice before the if statement, but that is not being set here. It's creating a completely different disaddice variable, that happens to have the same name, and when the id statement ends, that variable vanishes and the original disaddice variable has no value set. The brackets arent needed either.
1602708206
Pete
Pro
Marketplace Creator
Sheet Author
Ok, that helped. Now its returning a value, but not adding/subtracting. Instead its lumping them together, for instance instead of rolling (3+1) dice its rolling 31... Current Code: on("change:advantagetoggle change:advdisadvdice", function() { getAttrs(["advantagetoggle","advdisadvdice"], function(values) { console.log("xxx: "+values.advantagetoggle); let toggle = values.advantagetoggle; let dice=" "; let klkh=" "; if (toggle=="adv"){ dice="+"+values.advdisadvdice; klkh="kh"; } else if (toggle=="disadv") { dice="+"+values.advdisadvdice; klkh="kl"; } console.log("dice: "+dice); console.log("klkh: "+klkh); let advdice= parseInt(values.advdisadvdice) let disaddice=" "; let disklkh=" "; if (advdice=="0") { disaddice=(1); disklkh="kl"; } else if (toggle=="adv" && advdice > 0){ disaddice=(values.advdisadvdice-1); disklkh="kh"; } else { disaddice = (values.advdisadvdice+1) } console.log("dice: "+disaddice); console.log("klkh: "+disklkh); setAttrs({disaddice:disaddice,disklkh:disklkh,adDice:dice,klkh:klkh}); }); }); And, in case its the problem, the roll button I'm testing looks like this: {{roll=[[(@{wpnDice}@{disadDice})d6@{disklkh}@{wpnDice}+@{wpnBonus}]]}}
1602708571
GiGs
Pro
Sheet Author
API Scripter
What are the 3 and 1 in this case? this might be an error in your formula. Maybe this: {{roll=[[(@{wpnDice}@{adDice})d6@{klkh}@{wpnDice}+@{wpnBonus}]]}} should be {{roll=[[(@{wpnDice}+@{adDice})d6@{klkh}@{wpnDice}+@{wpnBonus}]]}}
1602708884

Edited 1602709088
Pete
Pro
Marketplace Creator
Sheet Author
The problem exists Here: else if(toggle=="disadv") { disaddice ="+"+(values.advdisadvdice+1) } I'm intending it to return the (value + 1) and it is instead returning the value&1. For instance if I set the advdisadvdice to be 2, it's returning 21 instead of 3. I'm able to fix the rest, just running into this problem.
1602720344
GiGs
Pro
Sheet Author
API Scripter
attributes in values are all strings by default. You need to coerce that into a number, using parseInt for example. Like                     else if(toggle=="disadv") { disaddice ="+"+((parseInt(values.advdisadvdice) || 0)+1) } or for increased clarity:                     else if(toggle=="disadv") {                         let tempdisad = parseInt(values.advdisadvdice) || 0; disaddice ="+"+(tempdisad +1) }
1602727865

Edited 1602727891
Pete
Pro
Marketplace Creator
Sheet Author
That's the spell I needed. Thank you again for your magical aid.
1602728090
GiGs
Pro
Sheet Author
API Scripter
hehe, you're welcome!