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

A little code help please, can't seem to get an attribute recognised

1626024956

Edited 1626025197
Darren H.
Pro
Sheet Author
I'm trying to improve my Shadowrun 2e sheet, and can't seem to get  Target Number Mods to apply from Deck Damage, if anyone can help me with code i would be appreciated.  Everytime I try to apply it to a roll  for example  +@{deckdam_pen} it says cannot find attribute. <input type="number" name="attr_deckdam_pen" value=0 style='display:none'>                             </td><td>                                 <input type="radio" name="attr_deckscon" value=0 CHECKED><span style="padding-left: 20px;">                             </td><td>                                 <input type="radio" name="attr_deckscon" value=1>                                 <input type="radio" name="attr_deckscon" value=2><span style="padding-left: 20px;">                             </td><td>                                 <input type="radio" name="attr_deckscon" value=3>                                 <input type="radio" name="attr_deckscon" value=4>                                 <input type="radio" name="attr_deckscon" value=5><span style="padding-left: 20px;">                             </td><td>                                 <input type="radio" name="attr_deckscon" value=6>                                 <input type="radio" name="attr_deckscon" value=7>                                 <input type="radio" name="attr_deckscon" value=8>                                 <input type="radio" name="attr_deckscon" value=9><span style="padding-left: 20px;">                             </td><td>                                 <input type="radio" name="attr_deckscon" value=10><span style="padding-left: 20px;"> and a text/worker on("change:deckscon", function() {         getAttrs(["deckscon"], function(v) {             var penalty = 0;             var deckscon = parseInt(v.deckscon);                          if (deckson > res) {                 if (deckson > 5) penalty = 3;                 else if (deckscon > 2) penalty = 2;                 else if (deckscon > 0) penalty = 1;             }                          setAttrs({"deckdam_pen": penalty});         });     });
1626026261
GiGs
Pro
Sheet Author
API Scripter
What is the code for the macro you are using, and are you launching it from a character sheet ability? Also change this <input type="number" name="attr_deckdam_pen" value=0 style='display:none'> to <input type="hidden" name="attr_deckdam_pen" value=0 > This is a better way to do hidden attributes.
1626026337

Edited 1626026370
GiGs
Pro
Sheet Author
API Scripter
Here is an issue. In your seet worker you have this line if (deckson > res) { but res isn't defined in the sheet worker. What is it? Also that says deckson, not deckscon.
1626026959
Darren H.
Pro
Sheet Author
if (deckson > res) { I have now deleted that, didn't need it. Checked all the spelling, I just can't seem to get it to work :/
1626027583
Darren H.
Pro
Sheet Author
I'm stumped.  On my Sandbox I have three characters, 2 characters it wont recognise it, 1 character it will but not apply the penelties!
1626029740

Edited 1626029863
GiGs
Pro
Sheet Author
API Scripter
What's the corrected code for the sheet worker? And do you have any other sheet workers before it in your script block? Finally, create an ability on a non-working character sheet, with the code: deckscon: @{deckscon} deckdam_pen: @{deckdam_pen} And each time you change deckscon, run that ability see what the attributes are being reported as.
1626033503
Darren H.
Pro
Sheet Author
I will try that...Also On one sheet worker is this, in this order... on("change:stun change:pain_res", function() {         getAttrs(["stun","pain_res"], function(v) {             var penalty = 0;             var stun = parseInt(v.stun);             var res = parseInt(v.pain_res);                          if (stun > res) {                 if (stun > 5) penalty = 3;                 else if (stun > 2) penalty = 2;                 else if (stun > 0) penalty = 1;             }                          setAttrs({"stun_pen": penalty});         });     });          on("change:wounds change:pain_res", function() {         getAttrs(["wounds","pain_res"], function(v) {             var penalty = 0;             var wounds = parseInt(v.wounds);             var res = parseInt(v.pain_res);                          if (wounds > res) {                 if (wounds > 5) penalty = 3;                 else if (wounds > 2) penalty = 2;                 else if (wounds > 0) penalty = 1;             }                          setAttrs({"wound_pen": penalty});         });     });          on("change:deckscon", function() {         getAttrs(["deckscon"], function(v) {             var penalty = 0;             var deckscon = parseInt(v.deckscon);                 {                 if (deckscon > 5) penalty = 3;                 else if (deckscon > 2) penalty = 2;                 else if (deckscon > 0) penalty = 1;             }                          setAttrs({"deckdam_pen": penalty});         });     }); The stun and wounds are the same format as Deck (as in a radio button format)  I used those scripts as a template top make one for the Deck damage. Should I put the Deck sheetworker in n a seperate section?
1626035036
GiGs
Pro
Sheet Author
API Scripter
You should keep all sheet workers in the same script block. I was asking because if there's a syntax error in an earlier worker, it can cause a correctly-written worker to fail. Do both of the first workers work correctly?
1626035323

Edited 1626035792
Darren H.
Pro
Sheet Author
Yes they work perfectly fine.  I might just have to go back to square one and start again with the script.  But if you can help find a reason why I’ll be grateful.  Thanks for your help so far. I just noticed above there is a bracket in the middle of my deck script, maybe it is that.  I’ll have a fiddle later.
1626040154
GiGs
Pro
Sheet Author
API Scripter
I dont know what to tell you - your code seems to be working perfectly. I created a sheet that contains code copied from above. I changed the deck_dam input - just removed the display:none style, so it was visible, so I could see if it was changing, and it worked perfectly. You're right that you can remove that { and } in the worker, it's not needed - but it doesn't stop it working. Also, those spans in your code seem a bit weirdly placed (and with no </span>) so I'd remove those, but they don't stop it working. So the error is somewhere else in your code. Here's the code I tried: < input   type = "number"   name = "attr_deckdam_pen"   value = 0   > </ td > < td >      < input   type = "radio"   name = "attr_deckscon"   value = 0   CHECKED >< span   style = " padding-left: 20px; " > </ td > < td >      < input   type = "radio"   name = "attr_deckscon"   value = 1 >      < input   type = "radio"   name = "attr_deckscon"   value = 2 >< span   style = " padding-left: 20px; " > </ td > < td >      < input   type = "radio"   name = "attr_deckscon"   value = 3 >      < input   type = "radio"   name = "attr_deckscon"   value = 4 >      < input   type = "radio"   name = "attr_deckscon"   value = 5 >< span   style = " padding-left: 20px; " > </ td > < td >      < input   type = "radio"   name = "attr_deckscon"   value = 6 >      < input   type = "radio"   name = "attr_deckscon"   value = 7 >      < input   type = "radio"   name = "attr_deckscon"   value = 8 >      < input   type = "radio"   name = "attr_deckscon"   value = 9 >< span   style = " padding-left: 20px; " > </ td > < td >      < input   type = "radio"   name = "attr_deckscon"   value = 10 >< span   style = " padding-left: 20px; " > < script   type = "text/worker" >     on("change:deckscon", function(info) {         console.log(info);         getAttrs(["deckscon"], function(v) {             var penalty = 0;             var deckscon = parseInt(v.deckscon);             {                 if (deckscon > 5) penalty = 3;                 else if (deckscon > 2) penalty = 2;                 else if (deckscon > 0) penalty = 1;             }             setAttrs({"deckdam_pen": penalty});         });     }); </ script >
1626043468
Darren H.
Pro
Sheet Author
Okay, thanks a lot.  I’ll just do the old copy and paste using your code and see if it works. Thanks for all your help, it’s greatly appreciated.