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

[HELP] setWithWorker not properly triggering Sheet Worker

1531544467
Missingquery
Pro
Sheet Author
API Scripter
I have a function on my sheet worker script that changes the attributes of a weapon when its uses reach 0 (essentially marking it unusable). Now, this script works perfectly fine when setting the value to 0 on the sheet itself. However, despite using the setWithWorker function, the uses attribute is set to 0, but the function does not activate. Furthermore, the setWithWorker does not respect the minimum & maximum values of the attribute field as dictated on the character sheet. ...Which is weird, because as I understand it, setWithWorker is supposed to be functionally the same thing as directly setting the values on the sheet. Have I overlooked something? Here is the relevant sheet workers code: on("change:repeating_weapons:uses", function(eventInfo) { console.log(eventInfo.newValue); if (eventInfo.newValue == "0" || eventInfo.newValue == 0){ console.log("Broken"); getAttrs(["repeating_weapons_WName"], function(v){ setAttrs({ "repeating_weapons_WRank": "UU", "repeating_weapons_WName": "Broken " + v["repeating_weapons_WName"] }); }); } }); And the API script code: UsesA.setWithWorker({current: Number(UsesA.get("current")) - 1}); log(UsesA.get("current"))
1531553923

Edited 1531555663
Jakob
Sheet Author
API Scripter
I would try writing the worker without newValue... it's pretty buggy. Since you have a getAttrs call in there anyway, you might as well tack on the uses there.
1531568922
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The API, and sheet workers for that matter, can ignore the range linitations. In addition to Jakob's suggestion, try using the API version of setattrs instead of setwithworker.
1531598494

Edited 1531598558
Missingquery
Pro
Sheet Author
API Scripter
When using the API version of setAttrs, how should I reference variables that contain strings? When I attempt to do something like: let CurrWR = "SwordEXP"; let CWRVal = 2; setAttrs(attacker.id, {CurrWR: CWRVal}); all that does is make a new attribute named CurrWR. Substituting in variables for the object value seems to work fine.
1531598903
Jakob
Sheet Author
API Scripter
setAttrs(attacker.id, { [CurrWR]: CWRVal });
1531599483
Missingquery
Pro
Sheet Author
API Scripter
Nope, that doesn't seem to work. I still get "Creating attribute: CurrWR"
1531619651
GiGs
Pro
Sheet Author
API Scripter
I'm a little confused by the OP. You say you have a sheet worker that isnt working properly, but you also reference an API script. If you are using an API script, you should post it in full. Also, it's a good idea to post the html of the repeating fieldset, and the full api script you are using. It seems like there might be an error somewhere in the code you havent posted.
1531620615

Edited 1531628885
Missingquery
Pro
Sheet Author
API Scripter
The API script can be found here and the sheet can be found here. Both are much too long to post in full (why I didn't post them originally), but you can take a look for yourself. I'm not having an issue with the repeating fieldset anymore, it's an entirely different attribute that I'm struggling with now. The relevant section of the API script is here . Edit: Nevermind, issue fixed!