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

Checkbox influencing checkbox

Hi there people, I'm trying to influence one checkbox with another one. Let me explain: I've set up a macro which will automatically put wound level on a character. Since the custom ruleset I use do not refer to a value, I've created checkbox that indicates the ''wound level''.  Some wound levels then have an impact on rolls, let's call it a ''roll modifier''.  I've created the roll modifier this way: <div class="hurtlvl"> <input type="checkbox" name="attr_hurtlvl" value="0"><span>Aucune (+0)</span> <input type="checkbox" name="attr_hurtlvl" value="-1"><span>Blessé (-1) // Assommé (-1)</span> <input type="checkbox" name="attr_hurtlvl" value="-2"><span>Blessure grave (-2) // Très assommé (-2)</span> </div> Then, in any skill check/attack/etc., I add a ''+ @{hurtlvl}'' to modify each roll (or not). So, I would like to link the checkbox ''wound level'' to the checkbox I use for ''roll modifier''. When attaining a certain threshold, the roll modifier would trigger. Is this making any sense? Guillaume
1573114698
GiGs
Pro
Sheet Author
API Scripter
What you want is a radio button, not a checkbox. Change type="checkbox" for each to type="radio" As it is, you have 3 separate checkboxes, using the same name, and that wont work. With radio buttons, only one can be selected at a time, and the value of the one selected will be used. I suggest also changing the value="0" one to include checked . That will set it as the default value, so it always has a value. Like so:                 <div class="hurtlvl"> <input type="radio" name="attr_hurtlvl" value="0" checked><span>Aucune (+0)</span> <input type="radio" name="attr_hurtlvl" value="-1"><span>Blessé (-1) // Assommé (-1)</span> <input type="radio" name="attr_hurtlvl" value="-2"><span>Blessure grave (-2) // Très assommé (-2)</span> </div>
Ok.  Well, that's definitely a more sensible way to do it. Also, I think I was getting around the "same name" problem because only one box could be check at all time. Anyway, this was working on my character sheet. But the thing is, I'm not enquiring on how to write my "roll modifier button" (thanks for the info though) but mostly how to influence a checkbox (or now radio button) with another checkbox. If the character has a "very hurt wound level", the roll modifier should catch this info and then apply a very hurt level result all around.
1573121365

Edited 1573121430
GiGs
Pro
Sheet Author
API Scripter
I guarantee your checkbox would not work the way you want, though it might appear to for a while. You cant have different attributes with the same name. (In fact, the only way to simulate this in html is to use a set of radio buttons.) I'm not clear on what you are asking for. Do you want another checkbox to modify the value of the the hurtlvl attribute? I'm not clear why you aren't simply using the radio button. Players can click their current wound level, and that attribute @{hurtlvl} will be applied to the roll. Your macro can set the hurtlvl attribute, either by adding 1 to its value (you'll have to check it doesnt go above max), or setting it directly.  If I'm not getting what you mean, I understand that can be frustrating. Can you explain more? Like, show the macro you are using so I can understand more clearly.
I'll try to explain things a bit more. Sorry if it's not really understandable.  I'm using the EZFudge system. In this system, you don't have a wounds total. You can get 3 ''scratchs'', one ''hurt'' condition, one ''very hurt'' condition and then you are out of action : I'm currently using checkboxes to represent wounds on the custom character sheet : <p><h4>Niveau de blessure:</h4></p> Scratch <input type="checkbox" name="attr_hurtaffiche" value="5"><span></span> <input type="checkbox" name="attr_hurtaffiche" value="4"><span></span> <input type="checkbox" name="attr_hurtaffiche" value="3"><span></span> <br> Hurt <input type="checkbox" name="attr_hurtaffiche" value="2"><span></span> <br> Very Hurt <input type="checkbox" name="attr_hurtaffiche" value="1"><span></span> <br> Unconscious<input type="checkbox" name="attr_hurtaffiche" value="0"><span></span> This section give me this output (in french, but you get the idea) : This value is modified when an successful attack is made on the target. I've set up my token so that  hurtaffiche  attribute is linked to the third bar. I'm using the Alterbar script (into the power cards script) to modify it. This specific line does the work : --?? $Esq.total <= $MS.total ?? alterbar1|_target|@{target||token_id} _bar|3 _amount|-[^DMG]/2+[^MS]/2 _show|GM So when an attack goes off, the bar #3 is modified and the  hurtaffiche   too. It's pretty useful and save me time. I can click on the character sheet or add number to the bar to modify everything. Even if everything is not perfect, it's viable. Now , the thing that I'm looking for : When a character is hurt (-1) or really hurt(-2), the EZFudge system impose a penalty on almost every roll. I've created this section to manage this effect : <p><h4>Condition affectant les résultats:</h4></p> <div class="advantagetoggle hurtlvl"> <input type="checkbox" name="attr_hurtlvl" value="0"><span>None (+0)</span> <br> <input type="checkbox" name="attr_hurtlvl" value="-1"><span> Hurt (-1) // Stun (-1)</span> <br> <input type="checkbox" name="attr_hurtlvl" value="-2"><span> Very Hurt (-2) // Very Stun (-2)</span> <br> </div> It give me a display resembling this : The thing is, it's a manual operation. To save me some time (and micromanagement), I would like the character sheet to identify the hurtlvl by itself and then apply the appropriate modifier. For exemple, if the character suffer a wound that bring the  attr_hurtaffiche  at a value of (1) (which is ''Very Hurt''), the character sheet should knows that a modifier of -2 should be applied to every roll I've previously identified for that character. Now, as a disclaimer, I know the custom system I've built for the wound system is not ideal. I've taken snip of code for different places to try and make everything work. I'm open to a different point of view. Hope it's a bit clearer.
1573207559

Edited 1573218245
GiGs
Pro
Sheet Author
API Scripter
aha, i know Fudge, I see the issue.  The radio button I suggested isnt the right way to handle this. But also what I said before about using the same attribute name for different checkboxes remains true. Your current naming scheme wont work. Also, there is a stumbling block. By default, scripts dont trigger sheet workers, and the solution to this will need a sheet worker responding to alterbars. It's possible to write a script to affect sheet workers, but we'll need to check if alterbars is written that way. Do you have a link to the script so I can check it? IIRC It's not in the script repository. If it does, here's roughly what we need to do: Change the name of all your current hurtlvl attributes, to include an identifier, which can be used to select it. The scratches might be scratch_1, attr_scratch_2, attr_scratch_3, then attr_hurt, attr_veryhurt, attr_incapacitated. Do any creatures in your game have different numbers of hurt/veryhurt levels? (I sincerely hope not, btw, because that makes the solution much  more complex.) Then create a hidden attribute named just attr_hurtlvl.  Have alterbars change the hurtlvl attribute. That will trigger a sheet worker, which will check the wound level and mark the correct box, and also handle wound overflow. It'll then return the hurtlvl attributes value to 0, so its ready for the next wound. If alterbars isnt written to support this, we can set up your tokenbar input so you can enter wound values manually. That'll require exactly the same changes as above. 
1573215655
GiGs
Pro
Sheet Author
API Scripter
Also, the damage section in alterbars: _amount|-[^DMG]/2+[^MS]/2 This looks like it can result in half values. If so, which way should they be rounded?
Here is the script :  alterBars Do any creatures in your game have different numbers of hurt/veryhurt levels?  No, every creature have the same hurt/very hurt level (which is only 1). You have 3 ''scratch'' level, one ''hurt'' and one ''very hurt''. Could go with 2 level of ''hurt'' though. Cause everybody tends to die pretty fast.   If so, which way should they be rounded? I want them to round down. I didn't include any ''floor'' command cause when I did some testing, this formula automatically included it. It never returns me half numbers. 
1573222370
GiGs
Pro
Sheet Author
API Scripter
Also, in your version of fudge, to the hurt and very hurt levels get added together, or do you use the highest? in other words, if someone is both hurt and veryhurt, do they have a -2 or -3 penalty?
GiGs said: Also, in your version of fudge, to the hurt and very hurt levels get added together, or do you use the highest? in other words, if someone is both hurt and veryhurt, do they have a -2 or -3 penalty? It's only the highest, so -2.
1573223548
GiGs
Pro
Sheet Author
API Scripter
Okay, here's the html you need (or at least, the html i used for testing). The important things here are the attribute names, types, and the values. You can delete or replace the spans. <h4>Niveau de blessure:</h4> Scratch <input type="checkbox" name="attr_scratch_1" value="1"><span></span> <input type="checkbox" name="attr_scratch_2" value="1"><span></span> <input type="checkbox" name="attr_scratch_3" value="1"><span></span> <br> Hurt <input type="checkbox" name="attr_hurt" value="1"><span>-1</span> <br> Very Hurt <input type="checkbox" name="attr_veryhurt" value="1"><span>-2</span> <br> Unconscious<input type="checkbox" name="attr_unconscious" value="1"><span>-</span> <input type="number" name="attr_hurtlvl" value="0"> <input type="hidden" name="attr_woundlvl" value="0"> hurtlvl is the actual total wound penalty, you can place it anywhere on the sheet, or make it hidden if you dont want it to be displayed to pcs. You can use it in your roll macros with @{hurtlvl}. woundlvl  is the value that you link to the token bar. When you enter a number here, it will trigger a sheet worker that will run to update the wound boxes, and wound total, and will then be reset to 0, read for the next wound. The sheet workers will be in the next post - got to go and get lunch. You didnt respond with a link to alterbars, so i cant check if that works with it.
Perfect! I'll check this out.  Regarding the Alterbar, it's stated in a previous message but was bunched up with the ''permalink-quote-report'' stuff. Guillaume B. said: Here is the script :  alterBars
1573224281

Edited 1573311495
GiGs
Pro
Sheet Author
API Scripter
I'll check that later. Dinner needed a few more minutes, so here's the sheet workers. There are two: the first updates wound penalties when you manually click a wound box, either to check it or to clear it. The second monitors the woundlvl box, so you can link a tokenbar to that and enter positive values to update wounds (1 = scratch, 2 = hurt, 3 = veryhurt, 4+ = unconscious). const woundlvls = {scratch_1: 0, scratch_2: 0, scratch_3: 0, hurt: 1, veryhurt: 2, unconscious: 10}; const woundnames = Object.keys(woundlvls); const woundPenalty = wounds => { const penalty = wounds.reduce((total, current, index) => { return total + current * woundlvls[woundnames[index]]; },0 ); return penalty >= 9 ? 0: (penalty > 2 ? 2 : penalty); }; // this one updates wound penalties when you manually click a wound box on(woundnames.map(wound => `change:${wound}`).join(' '), function() { getAttrs(woundnames, function(v) { let wounds = woundnames.map(lvl => +v[lvl] || 0); let penalty = woundPenalty(wounds); setAttrs({ hurtlvl: penalty }, {silent: true}); }); }); on('change:woundlvl', function(event) { getAttrs([...woundnames, 'woundlvl'], function(v) { // iterate through hurt levels, build an array of 0s and 1s to define whether that wound level is checked let wounds = woundnames.map(lvl => +v[lvl] || 0); // ==== GET VALUE OF NEW WOUND let newWound = Math.ceil((parseInt(v.woundlvl) || 0)/2); // if its 2+, need to add 2 to its value, to match the arrays above. if(newWound > 1) newWound += 2; // if its 0, routine ends, otherwise reduce value by 1, again to match above arrays. if(newWound < 1) { setAttrs({woundlvl: 0},{silent:true}); return; } newWound -= 1; // ==== ASSIGN WOUND // need to check whether rolled wound is currently 1, and if not, check upwards till a 0 is found let woundAssigned = -1; for(let i = newWound; i < woundnames.length; i++) { if(wounds[i] === 0) { wounds[i] = 1; woundAssigned = i; break; } } // this marks one wound, then exits the loop // if woundAssigned is still -1, no wound was assigned - every wound slot is filled. // ========= PREPARE OUTPUT const settings = {}; // resetthe wound box to 0. settings.woundlvl = 0; //calculate wound penalty settings['hurtlvl'] = woundPenalty(wounds); // update the wound boxess on the character sheet settings[woundAssigned < 0 ? "unconscious" : woundnames[woundAssigned]] = 1; //update the character sheet setAttrs(settings, {silent:true}); }); });
1573238755

Edited 1573270195
-G-
Pro
The implementation of the hurtlvl and woundlvl seems to work just fine. The -1 or -2 on all roll with the @{hurtlvl} is working too. The alterbar doesn't seems to function to influence the hurtlvl. Edit : After some testing, I can influence the result in the bar shown on the map. But to complete the operation, I need to click in the appropriate bar then hit enter. This sets the result for hurtlvl and restart the bar to ''0''. Also, this is how the damage influence the hurtlv: Result ( [^DMG]/2+[^MS]/2) Wounds 1-2 Scratch 3-4 Hurt 5-6 Very hurt 7+ unconscious  
1573311470

Edited 1573311917
GiGs
Pro
Sheet Author
API Scripter
To fix that damage range takes changing on line of code. From this: let newWound = parseInt(v.woundlvl) || 0; To this: let newWound = Math.ceil((parseInt(v.woundlvl) || 0)/2); I've changed it in the code above. At the moment you have to manually enter the value in the token bubble. I've tested alterbars, and I cant get it to update automatically. I've also tried with chatSetAttr (which directly changes attributes instead of bubbles), and that isnt working either.  I'm not sure if its an old bug with roll20 , or something about the structure of my sheet worker (but I dont see how that would be), but i cant test it now because of this other new bug . For crying out loud, roll20, get your act together.
1573313223

Edited 1573313329
-G-
Pro
I'm also having issue atm. The API output console gives me this: "Starting webworker script..." "Loading 0 translation strings to worker..." "SyntaxError: Unexpected identifier" "SyntaxError: Unexpected identifier\n at eval (<anonymous>)\n at messageHandler (evalmachine.<anonymous>:284:6)\n at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55)\n at emitTwo (events.js:106:13)\n at process.emit (events.js:194:7)\n at process.nextTick (internal/child_process.js:766:12)\n at _combinedTickCallback (internal/process/next_tick.js:73:7)\n at process._tickCallback (internal/process/next_tick.js:104:9)" "-=> Torch v0.8.13 <=- [Tue Aug 06 2019 01:03:02 GMT+0000 (UTC)]" "-=> AlterBars v2.0.5 <=- [Thu May 11 2017 12:52:56 GMT+0000 (UTC)]" "-=> Ammo v0.3.8 <=- [Tue Jul 31 2018 12:42:46 GMT+0000 (UTC)]" "-=> PowerCards v3.8.11 <=- [2018-02-16]" When I put the value in the token bubble, it doesn't update the character sheet anymore. I'll try later.
1573316378
GiGs
Pro
Sheet Author
API Scripter
To test the sheet functionality itself: Try disabling all scripts, then restart the sandbox. Then enter a value in the token bubble and see if it works. If wounds don't update, its not (probably) a script/API issue, and I can investigate it. But if it does work, it's an API issue, and I cant test it right now. I'd also double check any changes made to the sheet worker, just to make sure there's no typo there. " Unexpected identifier" could mean any number of things, but could be a typo or syntax error.
GiGs said: To test the sheet functionality itself: Try disabling all scripts, then restart the sandbox. Then enter a value in the token bubble and see if it works. If wounds don't update, its not (probably) a script/API issue, and I can investigate it. But if it does work, it's an API issue, and I cant test it right now. I'd also double check any changes made to the sheet worker, just to make sure there's no typo there. " Unexpected identifier" could mean any number of things, but could be a typo or syntax error. It's an API issue since it's updating just fine when every API is disabled. 
1573330588
GiGs
Pro
Sheet Author
API Scripter
It might have just been the system wide API glitch we had earlier today, that is now fixed.
Definitely, seems stable now. It's quite strange though that your script + Alterbar can't seems to update the token bar. Ah well, this is now a much smaller task anyway, thanks to you!
1573332946
GiGs
Pro
Sheet Author
API Scripter
Scripts by default cant trigger sheet workers. You need to write the script specifically to be able to do that, and alterbars wasnt written that way.  Whats confusing me is that another script that is written to do that isnt working, and my own hack of alterbars to do it isnt working either, so I'll have to do some proper testing when I get time. Might not be till some time during the week though.