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

select attribute to change

Hello everyone, I've been trying to replicate something using the Wiki, but I'm stuck because JavaScript is still new to me, and many things in Roll20 don't work the same way as they would elsewhere. I'm attempting to create a select menu to assign a +1 to an attribute... Specifically, I'm trying to implement "Euphoria" (mod +1 to selected attribute). <select name='attr_selecteuphoria'>     <option value='str'>STR</option>     <option value='con'>CON</option>     <option value='wis'>WIS</option>     <option value='mag'>MAG</option>     <option value='dex'>DEX</option>     <option value='int'>INT</option>     <option value='cha'>CHA</option> </select> and: <input name="attr_str_euphoria" type="hidden" value="0"> <input name="attr_dex_euphoria" type="hidden" value="0"> <input name="attr_con_euphoria" type="hidden" value="0"> <input name="attr_wis_euphoria" type="hidden" value="0"> <input name="attr_int_euphoria" type="hidden" value="0"> <input name="attr_cha_euphoria" type="hidden" value="0"> My Javascript looks something like this: on ( "change:selecteuphoria" , () => { getAttrs ([ "selecteuphoria" ], values => { const selectedStat = values. selecteuphoria ; let stat_mod = 0 ; if (selectedStat === "str" || selectedStat === "con" || selectedStat === "wis" || selectedStat === "mag" || selectedStat === "dex" || selectedStat === "int" || selectedStat === "cha" ) { stat_mod = "1" ; } setAttrs ({ [ `attr_ ${selectedStat} _mod_euphoria` ]: stat_mod }); log ( `Mod for ${selectedStat} set to: ${stat_mod} .` ); }); }); I tried to rewrite it from the wiki-one... But nothing happens. What's wrong? Are there any sources to learn R20-specific JS? Second question: Actually, our roll-buttons look like this: The roll button: <button type='roll' name="attr_rollWisdom" value='@{isgmroll} &{template:d20skillroll} {{rollheader=Wisdom}} {{whoroll=@{spokename}}} {{skillname=Wisdom}} {{rollresult=[[1d20 + @{LevelWisdom} [Base] + @{CalActWisdom} [Calculated Modifiers] + ?{Modifiers?|0} [dyn. Modifiers] ]]}}'> Wisdom</button> calculations: <input type='number' name='attr_CalActWisdom' value='@{wis_euphoria} + @{addJealous} + @{addHurt} + @{addInjury}' disabled /> Are there any options or possibilities to dynamically add or hide the options from my first question? In future, these calculations could be very long... And every roll gets lots of "0" in the mouseover-result-thing. Any suggestions or best practices are appreciated :) Thanks for help! :)
1715037255
GiGs
Pro
Sheet Author
API Scripter
Are there any sources to learn R20-specific JS? You could try <a href="https://cybersphere.me/roll20-sheet-author-master-list/" rel="nofollow">https://cybersphere.me/roll20-sheet-author-master-list/</a> and if it's specifically JS, check out the sheet worker section. Is your attribute inside a repeating section (fieldset) ?
1715037368
GiGs
Pro
Sheet Author
API Scripter
This part has an error: setAttrs ({ [ `attr_ ${selectedStat} _mod_euphoria` ]: stat_mod }); It should probably be setAttrs ({ [ ` ${selectedStat} _mod_euphoria` ]: stat_mod }); The attr_ part is just for roll20, to identify whether a stat is an attribute. You use it only in the HTML to create the attribute, and never use it in your own macros or sheet workers.
1715045478
GiGs
Pro
Sheet Author
API Scripter
Actually, it looks like that setAttrs line should be setAttrs ({ [ ` ${selectedStat} _euphoria` ]: stat_mod }); There's no "mod" in the file name.
1715096121

Edited 1715096164
GiGs
Pro
Sheet Author
API Scripter
Okay, in relation to your last question I just noticed another problem. when you have a line like this: setAttrs ({ [ ` ${selectedStat} _euphoria` ]: stat_mod }); That will change the selected value to "1" but if any previous attributes have ever been "1" it won't reset them to 0. So you really need a worker that changes all the stats. For this routine, it assumes you have an array of all the stat names, see the const stats = line. on ( "change:selecteuphoria" , () =&gt; { &nbsp; &nbsp; getAttrs ([ "selecteuphoria" ], values =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; const stats = [ "str" , "con" , "wis" , "mag" , "dex" , "int" , "cha" ] &nbsp; &nbsp; &nbsp; &nbsp; const selected_stat = values . selecteuphoria ; &nbsp; &nbsp; &nbsp; &nbsp; const output = (); &nbsp; &nbsp; &nbsp; &nbsp; stats . forEach ( stat =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output [ ` ${ stat } _euphoria` ] = ( selected_stat === stat ) ? 1 : 0 ; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ( output ); &nbsp; &nbsp; &nbsp; &nbsp; log ( `Mod for ${ selected_stat } set to 1.` ); &nbsp; &nbsp; }); }); If you add any stats , add their names to that array. You'll still need to add their attributes in the HTML (you can't avoid that without some sort of templating system).