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

HI.. help with a coding error!

hi. a silly bug.. but i cannot find it..&nbsp;&nbsp; when using the select options, only the ones above the 'campaign' work. as in the script/writer find the right pic and text. and its displayed. But any of the options below the 'Campaign' line.. nothing gets shown, it reverts to the default&nbsp; as if the top option was selected..&nbsp; 'value="0"' hope you can help..&nbsp; Thanks &lt;select name="attr_comsume" style="font-size: 15px"&gt; &lt;option value="0"&gt; -- STARTER -- &lt;/option&gt; &lt;option value="mana"&gt;Mana Potion&lt;/option&gt; &lt;option value="health"&gt;Health Potion&lt;/option&gt; &lt;option disabled style="background: #2F5126; color: white"&gt; -- COMMON -- &lt;/option&gt; &lt;option value="forge"&gt;Forge Gate Spell&lt;/option&gt; &lt;option value="focus"&gt;Focus Potion&lt;/option&gt; &lt;option value="exp"&gt;Experience Charm&lt;/option&gt; &lt;option value="sprint"&gt;Sprint Potion&lt;/option&gt; &lt;option value="knife"&gt;Throwing Knives&lt;/option&gt; &lt;option value="flask"&gt;Explosive Flask&lt;/option&gt; &lt;option value="endure"&gt;Endurance Potion&lt;/option&gt; &lt;option value="str"&gt;Strengh Potion&lt;/option&gt; &lt;option value="sta"&gt;Stamina Potion&lt;/option&gt; &lt;option value="greatm"&gt;Greater Mana Potion&lt;/option&gt; &lt;option value="greath"&gt;Greater Health Potion&lt;/option&gt; &lt;option disabled style="background: black; color: white"&gt; -- CAMPAIGN -- &lt;/option&gt; &lt;option disabled&gt; -- M D 1 -- &lt;/option&gt; &lt;option value="rbrave"&gt;Ring of Braveness&lt;/option&gt; &lt;option value="trollr"&gt;Troll Ring&lt;/option&gt; &lt;option value="rshadow"&gt;Ring of Shadow&lt;/option&gt; &lt;option value="rpower"&gt;Ring of Power&lt;/option&gt; &lt;option value="ggolds"&gt;Gnomish Gold Sack&lt;/option&gt; &lt;option value="crotect"&gt;Charm of Protection&lt;/option&gt; &lt;option value="magesc"&gt;Mages Charm&lt;/option&gt; &lt;option disabled&gt; -- M D 2 -- &lt;/option&gt; &lt;option value="phealth"&gt;Pendant of Health&lt;/option&gt; &lt;option value="feather"&gt;Micheals Feather&lt;/option&gt; &lt;option value="osouls"&gt;Orb of Souls&lt;/option&gt; &lt;option value="skeys"&gt;Soul Keys&lt;/option&gt; &lt;/select&gt; &lt;div class="sheet-2column" style="width: 100%"&gt; &lt;div class="sheet-col" style="width: 49%"&gt; &lt;img src=' ' name='attr_c_picture' style="height: 100px"&gt; &lt;/div&gt; &lt;div class="sheet-col" style="width: 49%"&gt; &lt;h4&gt;ABILITY&lt;/h4&gt; &lt;span name="attr_c_ability"&gt;&lt;/span&gt; &lt;h4&gt;USES&lt;/h4&gt; &lt;input type="number" name="attr_usess" max="5" min="0" value="1"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type='text/worker'&gt; on('change:comsume', function() { getAttrs(['comsume'], function(setting) { if (setting.comsume === 'mana') { setAttrs({ c_ability: '1 Use. +2 Mana.', c_picture: '<a href="https://i.imgur.com/tzOOyyf.jpg" rel="nofollow">https://i.imgur.com/tzOOyyf.jpg</a>'}); } else if (setting.comsume === 'health') { setAttrs({c_ability: '1 Use. +3 Health.', c_picture: '<a href="https://i.imgur.com/dCOlq7P.jpg" rel="nofollow">https://i.imgur.com/dCOlq7P.jpg</a>'}); } else if (setting.comsume === 'forge') { setAttrs({c_ability: '1 Use. Teleport to the nearest Forge.', c_picture: '<a href="https://i.imgur.com/ZFmMXt4.jpg" rel="nofollow">https://i.imgur.com/ZFmMXt4.jpg</a>'}); } else if (setting.comsume === 'focus') { setAttrs({c_ability: '1 Use. COMBAT: +2 rerolls.', c_picture: '<a href="https://i.imgur.com/huyPrqu.jpg" rel="nofollow">https://i.imgur.com/huyPrqu.jpg</a>'}); } else if (setting.comsume === 'exp') { setAttrs({c_ability: '1 Use. +3 Exp.', c_picture: '<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>'}); } else if (setting.comsume === 'sprint') { setAttrs({c_ability: '1 Use. Move up to 2 Zones.', c_picture: '<a href="https://i.imgur.com/EXLRUYx.jpg" rel="nofollow">https://i.imgur.com/EXLRUYx.jpg</a>'}); } else if (setting.comsume === 'knife') { setAttrs({c_ability: '1 Use. +3 Wounds to one Enemy in Line of Sight.', c_picture: '<a href="https://i.imgur.com/A1y0bA4.jpg" rel="nofollow">https://i.imgur.com/A1y0bA4.jpg</a>'}); } else if (setting.comsume === 'flask') { setAttrs({c_ability: '1 Use. +1 Wound to each Enemy in an adjacent Zone.', c_picture: '<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>'}); } else if (setting.comsume === 'endure') { setAttrs({c_ability: '1 Use. DEFENCE: +3 Blue.', c_picture: '<a href="https://i.imgur.com/ahVtJ48.jpg" rel="nofollow">https://i.imgur.com/ahVtJ48.jpg</a>'}); } else if (setting.comsume === 'str') { setAttrs({c_ability: '1 Use. ATTACK: +2 Orange.', c_picture: '<a href="https://i.imgur.com/aw38Qn1.jpg" rel="nofollow">https://i.imgur.com/aw38Qn1.jpg</a>'}); } else if (setting.comsume === 'sta') { setAttrs({c_ability: '1 Use. +1 Action.', c_picture: '<a href="https://i.imgur.com/J4qdYzx.jpg" rel="nofollow">https://i.imgur.com/J4qdYzx.jpg</a>'}); } else if (setting.comsume === 'greatm') { setAttrs({c_ability: '1 Use. +3 Mana.', c_picture: '<a href="https://i.imgur.com/OYb3QQC.jpg" rel="nofollow">https://i.imgur.com/OYb3QQC.jpg</a>'}); } else if (setting.comsume === 'greath') { setAttrs({c_ability: '1 Use. +5 Health.', c_picture: '<a href="https://i.imgur.com/COSlOxl.jpg" rel="nofollow">https://i.imgur.com/COSlOxl.jpg</a>'}); } else if (setting.consume === 'rbrave') { setAttrs({c_ability: '1 Use. DEFENCE: +2 Green.', c_picture: '<a href="https://i.imgur.com/JTvx2Ea.jpg" rel="nofollow">https://i.imgur.com/JTvx2Ea.jpg</a>'}); } else if (setting.consume === 'trollr') { setAttrs({c_ability: '1 Use. ACTION: +2 Health to All Heroes on the Tile.', c_picture: '<a href="https://i.imgur.com/WZ0c8bP.jpg" rel="nofollow">https://i.imgur.com/WZ0c8bP.jpg</a>'}); } else if (setting.consume === 'rshadow') { setAttrs({c_ability: '1 Use. ATTACK: In Shadow for this Attack.', c_picture: '<a href="https://i.imgur.com/OXG1myw.jpg" rel="nofollow">https://i.imgur.com/OXG1myw.jpg</a>'}); } else if (setting.consume === 'rpower') { setAttrs({c_ability: '1 Use. ATTACK: +1 Red.', c_picture: '<a href="https://i.imgur.com/m1V67fZ.jpg" rel="nofollow">https://i.imgur.com/m1V67fZ.jpg</a>'}); } else if (setting.consume === 'ggolds') { setAttrs({c_ability: '1 Use. During the Town-Phase, Use the Inventor for free.', c_picture: '<a href="https://i.imgur.com/51VQJJI.jpg" rel="nofollow">https://i.imgur.com/51VQJJI.jpg</a>'}); } else if (setting.consume === 'crotect') { setAttrs({c_ability: '2 Uses. 0 Health loss from Roaming Monsters when not in Combat. -1 Use: DEFENCE: +1 reroll.', c_picture: '<a href="https://i.imgur.com/BQXZmU7.jpg" rel="nofollow">https://i.imgur.com/BQXZmU7.jpg</a>'}); } else if (setting.consume === 'phealth') { setAttrs({c_ability: '2 Uses. -1 Use: COMBAT: -1 Wound.', c_picture: '<a href="https://i.imgur.com/KLFmSz5.jpg" rel="nofollow">https://i.imgur.com/KLFmSz5.jpg</a>'}); } else if (setting.consume === 'feather') { setAttrs({c_ability: '2 Uses. -1 Use: COMBAT: -1 die.', c_picture: '<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>'}); } else if (setting.consume === 'osouls') { setAttrs({c_ability: '2 Uses. -1 Use: ATTACK: Kiil a Minion.', c_picture: '<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>'}); } else if (setting.consume === 'skeys') { setAttrs({c_ability: '2 Uses. -1 Use: DEFENCE: +1 Frost.', c_picture: '<a href="https://i.imgur.com/K9DPCfV.jpg" rel="nofollow">https://i.imgur.com/K9DPCfV.jpg</a>'}); } else if (setting.consume === 'magesc') { setAttrs({c_ability: '3 Uses. -1 Use: ACTION: +2 Red. x Swords = -x Wounds to an Enemy in Spell range.', c_picture: '<a href="https://i.imgur.com/AcDuVKV.jpg" rel="nofollow">https://i.imgur.com/AcDuVKV.jpg</a>'}); } else { setAttrs({c_ability: ' ', c_picture: '<a href="https://i.imgur.com/C2uiKG5.jpg" rel="nofollow">https://i.imgur.com/C2uiKG5.jpg</a>'}); } }); }); &lt;/script&gt;
1680522992

Edited 1680523699
Maïlare
Pro
Sheet Author
API Scripter
Hello, First, you don't need to have setAttrs in all the conditions, just change variables values and make the setAttrs at the end. Second, I don't know the function(settings) &nbsp;but you can just use function(values) . Test this code (I have test it and it works), I have just replace the text values by numbers and delete the value of starter and make it disabled. Also, I don't know if all the number in the sheet worker are at the good place. &lt; select name = "attr_comsume" style = " font-size: 15px" &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option disabled &gt; -- STARTER -- &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "1" &gt; Mana Potion &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "2" &gt; Health Potion &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option disabled style = " background: #2F5126; color: white" &gt; -- COMMON -- &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "3" &gt; Forge Gate Spell &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "4" &gt; Focus Potion &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "5" &gt; Experience Charm &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "6" &gt; Sprint Potion &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "7" &gt; Throwing Knives &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "8" &gt; Explosive Flask &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "9" &gt; Endurance Potion &lt;/ option &gt; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "10" &gt; Strengh Potion &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "11" &gt; Stamina Potion &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "12" &gt; Greater Mana Potion &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "13" &gt; Greater Health Potion &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option disabled style = " background: black; color: white" &gt; -- CAMPAIGN -- &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option disabled &gt; -- M D 1 -- &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "14" &gt; Ring of Braveness &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "15" &gt; Troll Ring &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "16" &gt; Ring of Shadow &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "17" &gt; Ring of Power &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "18" &gt; Gnomish Gold Sack &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "19" &gt; Charm of Protection &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "20" &gt; Mages Charm &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option disabled &gt; -- M D 2 -- &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "21" &gt; Pendant of Health &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "22" &gt; Micheals Feather &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "23" &gt; Orb of Souls &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; option value = "24" &gt; Soul Keys &lt;/ option &gt; &lt;/ select &gt; &lt; div class = "sheet-2column" style = " width: 100%" &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; div class = "sheet-col" style = " width: 49%" &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; img src = ' ' name = 'attr_c_picture' style = " height: 100px" &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/ div &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; div class = "sheet-col" style = " width: 49%" &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; h4 &gt; ABILITY &lt;/ h4 &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; span name = "attr_c_ability" &gt;&lt;/ span &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; h4 &gt; USES &lt;/ h4 &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; input type = "number" name = "attr_usess" max = "5" min = "0" value = "1" /&gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/ div &gt; &lt;/ div &gt; on ( 'change:comsume' , function () { &nbsp;&nbsp;&nbsp;&nbsp; getAttrs ([ 'comsume' ], function ( values ) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var comsume = parseInt ( values . comsume ); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var abillity = '' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var picture = '' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( comsume === 1 ) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ability = '1 Use. +2 Mana.' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; picture = '<a href="https://i.imgur.com/tzOOyyf.jpg" rel="nofollow">https://i.imgur.com/tzOOyyf.jpg</a>' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if ( comsume === 2 ) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ability = '1 Use. +3 Health.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; picture = '<a href="https://i.imgur.com/dCOlq7P.jpg" rel="nofollow">https://i.imgur.com/dCOlq7P.jpg</a>' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if ( comsume === 3 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ability = '1 Use. Teleport to the nearest Forge.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; picture = '<a href="https://i.imgur.com/ZFmMXt4.jpg" rel="nofollow">https://i.imgur.com/ZFmMXt4.jpg</a>' ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if ( comsume === 4 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ability = '1 Use. COMBAT: +2 rerolls.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; picture = '<a href="https://i.imgur.com/huyPrqu.jpg" rel="nofollow">https://i.imgur.com/huyPrqu.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 5 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +3 Exp.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 6 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. Move up to 2 Zones.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/EXLRUYx.jpg" rel="nofollow">https://i.imgur.com/EXLRUYx.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 7 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +3 Wounds to one Enemy in Line of Sight.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/A1y0bA4.jpg" rel="nofollow">https://i.imgur.com/A1y0bA4.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 8 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +1 Wound to each Enemy in an adjacent Zone.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 9 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; ability = '1 Use. DEFENCE: +3 Blue.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/ahVtJ48.jpg" rel="nofollow">https://i.imgur.com/ahVtJ48.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 10 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. ATTACK: +2 Orange.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/aw38Qn1.jpg" rel="nofollow">https://i.imgur.com/aw38Qn1.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 11 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +1 Action.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/J4qdYzx.jpg" rel="nofollow">https://i.imgur.com/J4qdYzx.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 12 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +3 Mana.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/OYb3QQC.jpg" rel="nofollow">https://i.imgur.com/OYb3QQC.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 13 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. +5 Health.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/COSlOxl.jpg" rel="nofollow">https://i.imgur.com/COSlOxl.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 14 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. DEFENCE: +2 Green.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/JTvx2Ea.jpg" rel="nofollow">https://i.imgur.com/JTvx2Ea.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 15 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. ACTION: +2 Health to All Heroes on the Tile.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/WZ0c8bP.jpg" rel="nofollow">https://i.imgur.com/WZ0c8bP.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 16 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. ATTACK: In Shadow for this Attack.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/OXG1myw.jpg" rel="nofollow">https://i.imgur.com/OXG1myw.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 17 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. ATTACK: +1 Red.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/m1V67fZ.jpg" rel="nofollow">https://i.imgur.com/m1V67fZ.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 18 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '1 Use. During the Town-Phase, Use the Inventor for free.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/51VQJJI.jpg" rel="nofollow">https://i.imgur.com/51VQJJI.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 19 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '2 Uses. 0 Health loss from Roaming Monsters when not in Combat. -1 Use: DEFENCE: +1 reroll.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/BQXZmU7.jpg" rel="nofollow">https://i.imgur.com/BQXZmU7.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 20 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '2 Uses. -1 Use: COMBAT: -1 Wound.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/KLFmSz5.jpg" rel="nofollow">https://i.imgur.com/KLFmSz5.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 21 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '2 Uses. -1 Use: COMBAT: -1 die.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 22 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '2 Uses. -1 Use: ATTACK: Kiil a Minion.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 23 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '2 Uses. -1 Use: DEFENCE: +1 Frost.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/K9DPCfV.jpg" rel="nofollow">https://i.imgur.com/K9DPCfV.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( comsume === 24 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = '3 Uses. -1 Use: ACTION: +2 Red. x Swords = -x Wounds to an Enemy in Spell range.' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/AcDuVKV.jpg" rel="nofollow">https://i.imgur.com/AcDuVKV.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ability = ' ' ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picture = '<a href="https://i.imgur.com/C2uiKG5.jpg" rel="nofollow">https://i.imgur.com/C2uiKG5.jpg</a>' ; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c_ability: ability , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c_picture: picture &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); });
1680549024
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
To explain why Mailare's solution works, you had a typo in your code. In your html, you have attr_comsume , and for most of the js, you use comsume &nbsp;as the attribute name. However, about half way through your js if logic you switched to consume &nbsp;(note the n ). Mailare is absolutely correct that you shouldn't put the setAttrs in each if statement, but I'd also recommend streamlining this even more so that you don't have a huge line of if statements. Instead, we can store all this information in a lookup object and grab it very easily: const consumeSettings = { mana:{ability:'1 Use. +2 Mana.',picture:'<a href="https://i.imgur.com/tzOOyyf.jpg" rel="nofollow">https://i.imgur.com/tzOOyyf.jpg</a>'}, health:{ability:'1 Use. +3 Health.',picture:'<a href="https://i.imgur.com/dCOlq7P.jpg" rel="nofollow">https://i.imgur.com/dCOlq7P.jpg</a>'}, forge:{ability:'1 Use. Teleport to the nearest Forge.',picture:'<a href="https://i.imgur.com/ZFmMXt4.jpg" rel="nofollow">https://i.imgur.com/ZFmMXt4.jpg</a>'}, focus:{ability:'1 Use. COMBAT: +2 rerolls.',picture:'<a href="https://i.imgur.com/huyPrqu.jpg" rel="nofollow">https://i.imgur.com/huyPrqu.jpg</a>'}, exp:{ability:'1 Use. +3 Exp.',picture:'<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>'}, sprint:{ability:'1 Use. Move up to 2 Zones.',picture:'<a href="https://i.imgur.com/EXLRUYx.jpg" rel="nofollow">https://i.imgur.com/EXLRUYx.jpg</a>'}, knife:{ability:'1 Use. +3 Wounds to one Enemy in Line of Sight.',picture:'<a href="https://i.imgur.com/A1y0bA4.jpg" rel="nofollow">https://i.imgur.com/A1y0bA4.jpg</a>'}, flask:{ability:'1 Use. +1 Wound to each Enemy in an adjacent Zone.',picture:'<a href="https://i.imgur.com/UAPw7K7.jpg" rel="nofollow">https://i.imgur.com/UAPw7K7.jpg</a>'}, endure:{ability:'1 Use. DEFENCE: +3 Blue.',picture:'<a href="https://i.imgur.com/ahVtJ48.jpg" rel="nofollow">https://i.imgur.com/ahVtJ48.jpg</a>'}, str:{ability:'1 Use. ATTACK: +2 Orange.',picture:'<a href="https://i.imgur.com/aw38Qn1.jpg" rel="nofollow">https://i.imgur.com/aw38Qn1.jpg</a>'}, sta:{ability:'1 Use. +1 Action.',picture:'<a href="https://i.imgur.com/J4qdYzx.jpg" rel="nofollow">https://i.imgur.com/J4qdYzx.jpg</a>'}, greatm:{ability:'1 Use. +3 Mana.',picture:'<a href="https://i.imgur.com/OYb3QQC.jpg" rel="nofollow">https://i.imgur.com/OYb3QQC.jpg</a>'}, greath:{ability:'1 Use. +5 Health.',picture:'<a href="https://i.imgur.com/COSlOxl.jpg" rel="nofollow">https://i.imgur.com/COSlOxl.jpg</a>'}, rbrave:{ability:'1 Use. DEFENCE: +2 Green.',picture:'<a href="https://i.imgur.com/JTvx2Ea.jpg" rel="nofollow">https://i.imgur.com/JTvx2Ea.jpg</a>'}, trollr:{ability:'1 Use. ACTION: +2 Health to All Heroes on the Tile.',picture:'<a href="https://i.imgur.com/WZ0c8bP.jpg" rel="nofollow">https://i.imgur.com/WZ0c8bP.jpg</a>'}, rshadow:{ability:'1 Use. ATTACK: In Shadow for this Attack.',picture:'<a href="https://i.imgur.com/OXG1myw.jpg" rel="nofollow">https://i.imgur.com/OXG1myw.jpg</a>'}, rpower:{ability:'1 Use. ATTACK: +1 Red.',picture:'<a href="https://i.imgur.com/m1V67fZ.jpg" rel="nofollow">https://i.imgur.com/m1V67fZ.jpg</a>'}, ggolds:{ability:'1 Use. During the Town-Phase, Use the Inventor for free.',picture:'<a href="https://i.imgur.com/51VQJJI.jpg" rel="nofollow">https://i.imgur.com/51VQJJI.jpg</a>'}, crotect:{ability:'2 Uses. 0 Health loss from Roaming Monsters when not in Combat. -1 Use: DEFENCE: +1 reroll.',picture:'<a href="https://i.imgur.com/BQXZmU7.jpg" rel="nofollow">https://i.imgur.com/BQXZmU7.jpg</a>'}, magesc:{ability:'2 Uses. -1 Use: COMBAT: -1 Wound.',picture:'<a href="https://i.imgur.com/KLFmSz5.jpg" rel="nofollow">https://i.imgur.com/KLFmSz5.jpg</a>'}, phealth:{ability:'2 Uses. -1 Use: COMBAT: -1 die.',picture:'<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>'}, feather:{ability:'2 Uses. -1 Use: ATTACK: Kiil a Minion.',picture:'<a href="https://i.imgur.com/8mHR3S8.jpg" rel="nofollow">https://i.imgur.com/8mHR3S8.jpg</a>'}, osouls:{ability:'2 Uses. -1 Use: DEFENCE: +1 Frost.',picture:'<a href="https://i.imgur.com/K9DPCfV.jpg" rel="nofollow">https://i.imgur.com/K9DPCfV.jpg</a>'}, skeys:{ability:'3 Uses. -1 Use: ACTION: +2 Red. x Swords = -x Wounds to an Enemy in Spell range.',picture:'<a href="https://i.imgur.com/AcDuVKV.jpg" rel="nofollow">https://i.imgur.com/AcDuVKV.jpg</a>'}, }; on('change:comsume', function () { getAttrs(['comsume'], function (setting) { const itemObj = consumeSettings[setting.comsume] || {ability:'',picture:'<a href="https://i.imgur.com/C2uiKG5.jpg" rel="nofollow">https://i.imgur.com/C2uiKG5.jpg</a>'}; const setObj = { c_ability:itemObj.ability, c_picture:itemObj.picture } setAttrs(setObj,{silent:true}) }); });
Thanks guys..&nbsp;&nbsp; F.Y.I.&nbsp; I wrote it that way cause, thats the way i was shown. when learning how to code with 'script writer' commands Scott C.. welll spotted..&nbsp; it would be weeks, b4 i spotted that!