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 help please

1502723190
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I am trying to get this working. It is supposed to return the wound modifier value based on the selection of damage type. it is not returning the wound modifier. // Listen for sheet open or change to repeating type or remove type on('sheet:opened change:repeating_ranged_type remove:repeating_ranged_type', function (e) { updatewoundmod (); }) // Update Wound Modifer console.log('********* updatewoundmodifier *********'); function updatewoundmod (callback) { callback = callback || noop; getAttrs(['repeating_ranged_type'], function(v) { var attrs = {}; if (v.repeating_ranged_type === "Cutting (cut)") { repeating_ranged_wound_modifier = "1.5"; } else if (v.repeating_ranged_type === "Impaling (imp)") { repeating_ranged_wound_modifier = "2"; } else if (v.repeating_ranged_type === "Crushing (cr)") { repeating_ranged_wound_modifier = "1"; } else if (v.repeating_ranged_type === "Small Piercing (pi-)") { repeating_ranged_wound_modifier = "0.5"; } else if (v.repeating_ranged_type === "Piercing (pi)") { repeating_ranged_wound_modifier = "1"; } else if (v.repeating_ranged_type === "Large Piercing (pi+)") { repeating_ranged_wound_modifier = "1.5"; } else if (v.repeating_ranged_type === "Huge Piercing (pi++)") { repeating_ranged_wound_modifier = "2"; } else if (v.repeating_ranged_type === "Burning (burn)") { repeating_ranged_wound_modifier = "1"; } else if (v.repeating_ranged_type === "Corrosion (cor)") { repeating_ranged_wound_modifier = "1"; } else if (v.repeating_ranged_type === "Fatigue (fat)") { repeating_ranged_wound_modifier = "1"; } else if (v.repeating_ranged_type === "Toxic (tox)") { repeating_ranged_wound_modifier = "1"; } setAttrs( { repeating_ranged_wound_modifier: repeating_ranged_wound_modifier }, {silent: false}, callback ); }); }
1502724600
The Aaron
Pro
API Scripter
I'd suggest adding some logging to make sure you are getting back what you expect.  Also, a switch statement might be a bit more concise and easier to understand.  I'm betting that v.repeating_ranged_type is undefined and since you have no final else case, repeating_ranged_wound_modifier (which is never declared, btw) remains undefined.
1502725221
The Aaron
Pro
API Scripter
Actually, I think it's because these are repeating rows, you need to get the section IDs and iterate over them: <a href="https://wiki.roll20.net/Sheet_Worker_Scripts#getSe" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#getSe</a>... Will look something like this: /* ... */ &nbsp; &nbsp; getSectionIDs('repeating_ranged', function(ids){ &nbsp; &nbsp; &nbsp; &nbsp; var names = []; &nbsp; &nbsp; &nbsp; &nbsp; _.map(ids,function(id){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; names.push("repeating_ranged_"+id+"_type"); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; getAttrs(names, function(rows) { /* ... */
1502726228
The Aaron
Pro
API Scripter
You could write this with&nbsp; TheAaronSheet ( also ) like this: on('sheet:opened change:repeating_ranged_type remove:repeating_ranged_type', function (e) { &nbsp; updatewoundmod (); }); function updatewoundmod(callback){ &nbsp; callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop &nbsp; TAS.repeating('ranged') &nbsp; &nbsp; .fields('type','wound_modifier') &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r.type){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); };
1502726538
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
let me plug that last in and see what's what...
1502726822

Edited 1502726889
Jakob
Sheet Author
API Scripter
The event would be "sheet:opened change:repeating_ranged:type remove:repeating_ranged". Also, the remove event is totally superfluous, so it really should be "sheet:opened change:repeating_ranged:type".
1502726888
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
That last did not have the desired effect. Could it be because of the html for the attr? &lt;input type="number" name="attr_wound_modifier" value="0" disabled="disabled"/&gt; or should it be this? &lt;input type="number" name="attr_wound_modifier" value="0" readonly="readonly"/&gt;
1502726942
Jakob
Sheet Author
API Scripter
It should definitely be readonly and not disabled.
1502727127
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
No effect on wound_modifier
1502727253
The Aaron
Pro
API Scripter
Are you getting errors or just now change? (and you included TheAaronSheet code in your sheet workers?)
1502727270

Edited 1502781946
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Here is the&nbsp;game if anyone is interested in looking at what I have done to update the GURPS to 4e
1502727331
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
What's this magical Aaron sheet code you speak of Aaron?
1502727516
The Aaron
Pro
API Scripter
If you're using the last code I posted last, you'd need to insert this file in the top of your sheet worker section:&nbsp; <a href="https://github.com/shdwjk/TheAaronSheet/blob/maste" rel="nofollow">https://github.com/shdwjk/TheAaronSheet/blob/maste</a>... Also, I can't join from the link you posted. &nbsp;I would only be able to see the sheet in game, not monkey with the source from there, but that's probably fine.
1502727605
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
it worked and thank you so very much sir
1502727715
The Aaron
Pro
API Scripter
Sweet. =D &nbsp;No problem.
1502727768
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Now the next task will be to learn how to move an API to sheetworker status. ;)
1502728141
The Aaron
Pro
API Scripter
eh? &nbsp;=D
1502728371
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
The roll parser that I never got to work with my roll template...I am thinking that I could convert it into a sheet worker.
1502728509
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I am learning this as I go btw
1502729543
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
next question: In order to do one for melee weapons (a separate repeating area) should i make another script except 'melee' or can we combine the two in the same script?
1502730279
The Aaron
Pro
API Scripter
All things being equal, you'd just create another function that does .repeating('melee'). &nbsp;You could also refactor the above like this, if all the other names are the same: on('sheet:opened change:repeating_ranged_type remove:repeating_ranged_type', function (e) { &nbsp; updatewoundmod ('ranged'); }); on('sheet:opened change:repeating_melee_type remove:repeating_melee_type', function (e) { &nbsp; updatewoundmod ('melee'); }); function updatewoundmod(repeatingName, callback){ &nbsp; callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop &nbsp; TAS.repeating(repeatingName) &nbsp; &nbsp; .fields('type','wound_modifier') &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r.type){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); }; Though I have some recollection that there is an issue with having repeating row fields with the same name as other repeating row fields in another repeating section. &nbsp;It's best to preface repeating row fields with their repeating section name like: &lt;input type="number" name="attr_ranged_wound_modifier" value="0" readonly="readonly"/&gt; In which case you could do: on('sheet:opened change:repeating_ranged_rangedtype remove:repeating_ranged_rangedtype', function (e) { &nbsp; updatewoundmod ('ranged'); }); on('sheet:opened change:repeating_melee_melee_type remove:repeating_melee_melee_type', function (e) { &nbsp; updatewoundmod ('melee'); }); function updatewoundmod(repeatingName, callback){ &nbsp; callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop &nbsp; TAS.repeating(repeatingName) &nbsp; &nbsp; .fields( repeatingName+'_type', repeatingName+'wound_modifier' ) &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r[repeatingName+'_type']){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r[repeatingName+'_wound_modifier'] = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r[repeatingName+'_wound_modifier'] = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r[repeatingName+'_wound_modifier'] = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r[repeatingName+'_wound_modifier'] = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); }; It's been awhile since I touched sheet workers though, so I might be misremembering.
1502733764

Edited 1502734480
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
So it looks like that issue with&nbsp;repeating row fields with the same name as other repeating row fields is still there. So i inserted ranged before type and wound_modifier and that seems to break it. on('sheet:opened change:repeating_ranged_rangedtype remove:repeating_ranged_rangedtype', function (e) { &nbsp; updatewoundmod (); }); function updatewoundmod(callback){ &nbsp; callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop &nbsp; TAS.repeating('ranged') &nbsp; &nbsp; .fields('rangedtype','rangedwound_modifier') &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r.rangedtype){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); }; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.rangedwound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); };
1502735099
The Aaron
Pro
API Scripter
Cool, glad I could help! =D
1502735463
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Still wasnt working after the change...so I am scratching my head.
1502735792
The Aaron
Pro
API Scripter
You updated the attributes to match the rangedtype and such?
1502735852
The Aaron
Pro
API Scripter
Oh..&nbsp; on('sheet:opened change:repeating_ranged:rangedtype', function (e) {
1502735886
The Aaron
Pro
API Scripter
I didn't take Jakob's changes into account.
1502735980
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
So I went back to plan A and made a whole other script replacing "ranged" with "melee". Problem solved see final result below: // Wound Modifier Script on('sheet:opened change:repeating_ranged:type remove:repeating_ranged:type', function (e) { updatewoundmod (); }); function updatewoundmod(callback){ callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop TAS.repeating('ranged') &nbsp; &nbsp; .fields('type','wound_modifier') &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r.type){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); }; on('sheet:opened change:repeating_melee:type remove:repeating_melee:type', function (e) { updatewoundmod (); }); function updatewoundmod(callback){ callback = callback || noop; &nbsp;// assuming noop is defined somewhere, otherwise _.noop TAS.repeating('melee') &nbsp; &nbsp; .fields('type','wound_modifier') &nbsp; &nbsp; .each(function(r){ &nbsp; &nbsp; &nbsp; switch(r.type){ &nbsp; &nbsp; &nbsp; &nbsp; case "Small Piercing (pi-)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "0.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Large Piercing (pi+)": &nbsp; &nbsp; &nbsp; &nbsp; case "Cutting (cut)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1.5"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Huge Piercing (pi++)": &nbsp; &nbsp; &nbsp; &nbsp; case "Impaling (imp)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "2"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "Burning (burn)": &nbsp; &nbsp; &nbsp; &nbsp; case "Corrosion (cor)": &nbsp; &nbsp; &nbsp; &nbsp; case "Fatigue (fat)": &nbsp; &nbsp; &nbsp; &nbsp; case "Toxic (tox)": &nbsp; &nbsp; &nbsp; &nbsp; case "Piercing (pi)": &nbsp; &nbsp; &nbsp; &nbsp; case "Crushing (cr)": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.wound_modifier = "1"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); };
1502737090
The Aaron
Pro
API Scripter
Cool. So long as you got it working. =D
1502737138
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Aaron, I cannot speak on behalf of everyone but, I have to give you a great big thanks for all of your help. Especially since, you are probably one of the busiest people here on Roll20. Without you there are many things that just won't get done. You and all of your work is highly appreciated. Thank you so very much.
1502737200
The Aaron
Pro
API Scripter
=D &nbsp;No worries, I enjoy helping. You're welcome!
1502782075
Gen Kitty
Forum Champion
I cleaned up the join links, so you don't get mischief demons running amok ;)&nbsp; If someone still needs the link, they can PM for it.