[Script] ChatSetAttr - set character attributes via chat messages

1484671169
Is it happy dance time? Riley rolled out that change you needed. 
1484684399
Jakob
Pro
Sheet Author
API Scripter
I just pushed 1.2 The script now uses the new setWithWorker functionality by default. A toggle in the options exists to return to the old attr.set() behaviour. A word of caution: some initial testing seems to show that setWithWorker does not work very reliably yet. But at least the functionality is there now...
1484692433
When you say reliable are you speaking of time to do or it just never gets done? I have noticed the API seem very, very slow to load today in general. 
1484693387

Edited 1484693398
Jakob
Pro
Sheet Author
API Scripter
Gary W. said: When you say reliable are you speaking of time to do or it just never gets done? I have noticed the API seem very, very slow to load today in general.  I've had some cases where it didn't work at all, but haven't tried a serious reproduction so far. The long loading time is because it builds an index of all your campaign objects when the API starts up now. This can take quite a while if the campaign has a lot of characters. On the plus side, it makes certain API functions significantly faster.
1484747969
Jakob
Pro
Sheet Author
API Scripter
I added the fix for repeating sections into 1.2. repeating_blabla_$5_snizzle should now always refer to the attribute snizzle as seen in the 6th row of the repeating_blabla section on the character sheet.
1484802986

Edited 1484803082
Vince
Pro
Sheet Author
I was all excited with the new update to the API... On the Pathfinder sheet, I just tried !setattr --sel --repeating_buff_-kap1fyvzj0xx7fhbq0k_buff-enable_toggle|1 which toggles the buff, but this is still not recognized by the sheet sheet worker. Thoughts?
1484803059

Edited 1484803140
The Aaron
Pro
API Scripter
Likely this:  https://app.roll20.net/forum/permalink/4514812/ and this:  https://app.roll20.net/forum/permalink/4513979/
1484803089
The Aaron
Pro
API Scripter
Summary:  Sheet worker checks that the source is 'player', but the source is 'api'.  
1484803139
Vince
Pro
Sheet Author
I'm using our latest code with the changes made for the API update...
1484803182
The Aaron
Pro
API Scripter
Then I've got nothing! =D
1484803354
chris b.
Pro
Sheet Author
is it 'api' in small letters? that is what it looks for: eventInfo.sourceType === 'api' || eventInfo.sourceType === 'player' I changed everything to the above.
1484803501
Vince
Pro
Sheet Author
So, it looks like the api script must include the code needed to send source "player" to the sheet in order for sheet workers to recognize the change?  
1484806623
Jakob
Pro
Sheet Author
API Scripter
Vince said: So, it looks like the api script must include the code needed to send source "player" to the sheet in order for sheet workers to recognize the change?   I don't think so, if chris has changed it everywhere and if indeed webworkers simply have a sourceType of 'api' instead of 'player'.
1484808011

Edited 1484808550
Vince
Pro
Sheet Author
Thanks Jakob.  I can't seem to get any event detection from sheet workers using the script. ;-( I can see the changes that Chris has made, example on("change:recalc1 change:migrate1", TAS.callback(function eventRecaluateSheet(eventInfo) { TAS.debug("caught " + eventInfo.sourceAttribute + " event: " + eventInfo.sourceType); if (eventInfo.sourceType === "player" || eventInfo.sourceType === "api") { checkForUpdate(); } })); but even changing recalc1 "!setattr --sel --recalc1|1"  doesn't fire an event.
1484809090
Jakob
Pro
Sheet Author
API Scripter
Vince said: Thanks Jakob.  I can't seem to get any event detection from sheet workers using the script. ;-( I can see the changes that Chris has made, example on("change:recalc1 change:migrate1", TAS.callback(function eventRecaluateSheet(eventInfo) { TAS.debug("caught " + eventInfo.sourceAttribute + " event: " + eventInfo.sourceType); if (eventInfo.sourceType === "player" || eventInfo.sourceType === "api") { checkForUpdate(); } })); but even changing recalc1 "!setattr --sel --recalc1|1"  doesn't fire an event. I would discuss it in the API changes thread; as long as you use version 1.2 of the script and have not deactivated the use of sheet workers, it just calls setWithWorkers(). If that does not fire the event, I cannot do anything about it, you'll have to take it up with Riley ;).
1484809319
Vince
Pro
Sheet Author
Sounds good.  Thanks
1484842766

Edited 1484842800
When you guys get this all sorted out I hope you can provide a nice example to reference.  I'm hoping to map token bars to things like 'Channel Energy' or 'Arcane Pool' points. Thank you again for all your hard work!
1484843220
Jakob
Pro
Sheet Author
API Scripter
Sudain said: When you guys get this all sorted out I hope you can provide a nice example to reference.  I'm hoping to map token bars to things like 'Channel Energy' or 'Arcane Pool' points. Thank you again for all your hard work! Thanks! So, attributes like spell slots, channel energy pools, or arcane pools usually wouldn't have sheet workers attached to them, so you should be able to modify them freely already. Moreover, for anything token-related, you probably want TokenMod. But I must say I'm a bit confused on what you're actually planning to do here :). Can you elaborate?
1484843403

Edited 1484843544
Ah, maybe I'm doing it wrong.  :) The intent is to have the players tokens mapped to their character sheets (or represent those sheets).  Then have HP connected to the green bar(arbitrary), and then other class specific features they need to keep track of mapped to the other two bars.  Mostly to help me the GM realize that "hey, they are low on resources." or "That barbarian is out of rages for the day, but he said he just raged...  interesting..."  That's the end goal, and maybe I'm getting my mods mixed up as you said.  :D Edit: I am mixing up tokenmod and this one.  I do use this one extensively when creating monsters with roll queries.  This has saved me a great deal of time creating the monsters, though the sheet updates have reset several key variables (like ac) on monsters over time.  But that's an issue for a different thread.  :D
1484843823
Jakob
Pro
Sheet Author
API Scripter
Sudain said: Ah, maybe I'm doing it wrong.  :) The intent is to have the players tokens mapped to their character sheets (or represent those sheets).  Then have HP connected to the green bar(arbitrary), and then other class specific features they need to keep track of mapped to the other two bars.  Mostly to help me the GM realize that "hey, they are low on resources." or "That barbarian is out of rages for the day, but he said he just raged...  interesting..."  That's the end goal, and maybe I'm getting my mods mixed up as you said.  :D Okay, that sounds like a mix-up ;). I assume that the class resources are in repeating sections, which is why you cannot link them normally? If yes, implementing this properly requires a special-purpose script that keeps your repeating resource counter in sync with some non-repeating attribute (don't know if there is one around somewhere). Neither TokenMod nor ChatSetAttr can do this.
1484844216
Correct, I can't set them normally.  I haven't seen token mod or chatsetattr do it yet so I've just been telling the players to check their tokens when they get on the map.
1484845213
The Aaron
Pro
API Scripter
Sudain said: Ah, maybe I'm doing it wrong.  :) The intent is to have the players tokens mapped to their character sheets (or represent those sheets).  Then have HP connected to the green bar(arbitrary), and then other class specific features they need to keep track of mapped to the other two bars.  Mostly to help me the GM realize that "hey, they are low on resources." or "That barbarian is out of rages for the day, but he said he just raged...  interesting..."  That's the end goal, and maybe I'm getting my mods mixed up as you said.  :D Edit: I am mixing up tokenmod and this one.  I do use this one extensively when creating monsters with roll queries.  This has saved me a great deal of time creating the monsters, though the sheet updates have reset several key variables (like ac) on monsters over time.  But that's an issue for a different thread.  :D This is what I use to setup tokens for PCs: !token-mod {{   --on showname      light_hassight      showplayers_name      showplayers_bar1      showplayers_bar2      showplayers_bar3      showplayers_aura1      showplayers_aura2   --off isdrawing    --set represents|"?{Character Name}"       bar1_link|AC     bar2_link|Speed     bar3_link|HP     light_radius|5      light_dimradius|=-5  }} Does that cover your use case?
1484845746
For the normally available attributes, yes.  For the repeating attributes that a character sheet may or may not have depending on their class abilities, not yet.  Or at least I haven't been able to get it to work.  I'll try again when I get home tonight. Thank you for the help!
1484848910
The Aaron
Pro
API Scripter
Ah, for repeating, that's unlikely to work. =/  I'll have to experiment with that.
1484864317
Jakob- the new version of chatsetattr is working very reliably for me so far. Have used it to apply the global bonus for crusaders mantle and bless. Worked every time.
1484887956
The Aaron said: This is what I use to setup tokens for PCs: !token-mod {{   --on showname      light_hassight      showplayers_name      showplayers_bar1      showplayers_bar2      showplayers_bar3      showplayers_aura1      showplayers_aura2   --off isdrawing    --set represents|"?{Character Name}"       bar1_link|AC     bar2_link|Speed     bar3_link|HP     light_radius|5      light_dimradius|=-5  }} Very handy! It may be a weird side effect of my sheet (customized from Diana's D&D 3.5 one), but does bar x _link not work for autocalc fields? My armorclass field does not show on the bar after running this. I have changed the above to match the Attribute names in my sheet, and armorclass displays in the sheet. I can manually link the bar to armorclass just fine. My speed and hitpoints fields are just straight text inputs and TokenMod adds them with no problem.
1484916787
The Aaron
Pro
API Scripter
It may not work for auto calc fields.  I seem to recall Kryx had found a hack for that a long time ago.  I need to revisit that topic.
1485334950
Jakob
Pro
Sheet Author
API Scripter
Vince said: Thanks Jakob.  I can't seem to get any event detection from sheet workers using the script. ;-( [...] but even changing recalc1 "!setattr --sel --recalc1|1" doesn't fire an event. Any change? Does it work now?
1485335510
Vince
Pro
Sheet Author
Still the same.  I can see the recalc button change state, but the console log never shows the recalc event detection so sheet workers appear to have no clue anything has changed.
1485346887
Jakob
Pro
Sheet Author
API Scripter
Vince said: Still the same.  I can see the recalc button change state, but the console log never shows the recalc event detection so sheet workers appear to have no clue anything has changed. That's a shame, it works just fine for me with the Shaped sheet.
1485350140
It has  been lightning fast for me on shaped sheet as well. Flawless
1485359504
Vince
Pro
Sheet Author
Jakob said: Vince said: Still the same.  I can see the recalc button change state, but the console log never shows the recalc event detection so sheet workers appear to have no clue anything has changed. That's a shame, it works just fine for me with the Shaped sheet. Not sure what's wrong.  I believe Chris has made the proper changes and I can see some info in the API log about the PF sheet.  There are no errors and the ChatSetattr seems ti be functioning fine other than the sheet not recognizing the event.  I'm using 1.2 from github.
1485397405

Edited 1485397439
Vince
Pro
Sheet Author
I may have been testing with the wrong version of ChatSetAttr... I think the old and new code both had v1.2 but I noticed the date was newer when I double checked tonight.  ;-P   So now I definitely have the the version I need.   Anyhow when I try getting the script to trigger the recalc I noticed the API log has an error about "performance" being undefined. It looks like it's part of TAS. error: "ReferenceError: performance is not defined" "ReferenceError: performance is not defined\n at Array.TAS_CALLSTACK_1 (eval at <anonymous> (eval at <anonymous> (evalmachine.<anonymous>:282:6)), <anonymous>:3:99)\n at self.trigger (evalmachine.<anonymous>:77:37)\n at messageHandler (evalmachine.<anonymous>:285:11)\n at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:68:55)\n at emitTwo (events.js:100:13)\n at process.emit (events.js:185:7)\n at handleMessage (internal/child_process.js:695:10)\n at Pipe.channel.onread (internal/child_process.js:440:11)" Thoughts?  Is this completely a sheet issue?  Thanks
1485400701
The Aaron
Pro
API Scripter
You're using this patch:   https://github.com/shdwjk/TheAaronSheet/pull/1/fil... I don't believe the performance object exists outside the browser. You could either add some sort of polyfill like: var performance = performance || {now:_.now}; or switch to vanilla TAS.
1485401512

Edited 1485406508
Vince
Pro
Sheet Author
Thanks Aaron.  I added in the variable line but I'm getting the same error message... callstack = getCallstack(); callstack.shift(); return (function (cb, ctx, cs, lbl) { var ctxref = registerCallstack(cs, lbl); /*jshint -W054 */ var performance = performance || {now:_.now}; return new Function('cb', 'ctx', 'TASlog', "return function TAS_CALLSTACK_" + ctxref + "(){" + "TASlog('Entering: '+(cb.name||'(anonymous function)'));" + "var t0 = performance.now();cb.apply(ctx||{},arguments);var t1 = performance.now();" + "TASlog('Exiting: '+(cb.name||'(anonymous function)')+' (took '+Number(Math.round((t1-t0)+'e3')+'e-3')+' ms)');" + "};")(cb, ctx, log); /*jshint +W054 */ } (callback, context, callstack, label)); API log(the last two lines only happen when I run **!setattr --sel --recalc1|1**  ) "ReferenceError: performance is not defined" "ReferenceError: performance is not defined\n    at Array.TAS_CALLSTACK_1 (eval at <anonymous> (eval at <anonymous> (evalmachine.<anonymous>:282:6)), <anonymous>:3:99)\n    at self.trigger (evalmachine.<anonymous>:77:37)\n    at messageHandler (evalmachine.<anonymous>:285:11)\n    at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:68:55)\n    at emitTwo (events.js:100:13)\n    at process.emit (events.js:185:7)\n    at handleMessage (internal/child_process.js:695:10)\n    at Pipe.channel.onread (internal/child_process.js:440:11)"
1485401701
The Aaron
Pro
API Scripter
You'll need to add it before TAS.
1485402610
Vince
Pro
Sheet Author
Moved the variable line to directly before TAS // Contact: https://app.roll20.net/users/104025/the-aaron var performance = performance || {now:_.now}; var TAS = TAS || (function () { and wow, no errors, but ALL the DEBUG lines from sheet workers get posted to the API console.   The browser's console still doesn't show "... Triggering for change:recalc1 VM30:181 TAS: Entering: eventRecaluateSheet VM30:181 DEBUG: caught recalc1 event: player VM30:181 TAS: Exiting: eventRecaluateSheet (took 0 ms) sheetsandboxworker.js?20160926:57 Triggering for change:recalc1_max ..." Which is the normal log output if I actually toggle recalc1 manually.
1485402855
The Aaron
Pro
API Scripter
So, that's to be expected if it runs in the API, right? If you manually change things on the sheet in the game, does it log to the console?
1485403254
Vince
Pro
Sheet Author
The Aaron said: So, that's to be expected if it runs in the API, right? If you manually change things on the sheet in the game, does it log to the console? I guess I was expecting to see the same browser's console log output of sheet worker activity regardless if the sheet was triggered by an API script.  I assume I was wrong?  ;-P
1485403784
The Aaron
Pro
API Scripter
Probably.  I've not experimented with it, but the whole point of that work was so the API could be "one of the players" with regard to sheet workers.  The sheet worker is running in the context of the API (not a browser, Node 6.5 or so) which is why the performance object fails to be located in that function.  The practical upshot being that the API Console is your sheet's console when your sheet is running on the API.
1485404262
Vince
Pro
Sheet Author
Thanks for leading me to the light Aaron.  ;-) So now, Pathfinder users can toggle Buffs from a macro!  Tested and works! !setattr --sel --repeating_buff_$0_buff-enable_toggle|1 or using rowid !setattr --sel --repeating_buff_-Kap1fyVzj0xX7Fhbq0K_buff-enable_toggle|1 Awesome! Follow up question; I can set values using ChatSetAttr, but what if I simply want to toggle between on/off 1|0?
1485404562
The Aaron
Pro
API Scripter
As in, you just want to reverse the current value? !setattr --sel --repeating_buff_$0_buff-enable_toggle|[[1-(1*@{repeating_buff_$0_buff-enable_toggle})]]
1485406223

Edited 1485406307
Vince
Pro
Sheet Author
Yes!  Thank you (I had to add " selected| ") It's cool, you're still human... ;-P !setattr --sel --repeating_buff_$0_buff-enable_toggle|[[1-(1*@{selected|repeating_buff_$0_buff-enable_toggle})]]
1485406567
The Aaron
Pro
API Scripter
Hey, I can't do everything for you... =D
1485406634
Vince
Pro
Sheet Author
The Aaron said: Hey, I can't do everything for you... =D Who says?  You must have been talking to Stephen...
1485406902
The Aaron
Pro
API Scripter
Not in hours! =D
1485413029
Jakob
Pro
Sheet Author
API Scripter
Glad it works now! I am slightly confounded though, everything I've uploaded that is titled ChatSetAttr 1.2 had sheet workers included ... anyway, doesn't matter now. Bonus: toggling buffs on multiple characters (untested, but should work). !setattr --evaluate --repeating_buff_$0_buff-enable_toggle|1-%repeating_buff_$0_buff-enable_toggle% Just need to add a targeting option.
1485413405
The Aaron
Pro
API Scripter
Ah yeah, that 1* bit isn't even needed...  Man, I'm getting more "human" all the time!
1485414022
Vince
Pro
Sheet Author
Thanks guys.   @Jakob   I'll have to mod that to toggle Conditions on multiple characters.  Can't wait to hear the player's all freak out... ;-)
1485550860
Nibrodooh
Pro
Sheet Author
hello, in the latest version of the script from the 1 click install (1.2) I seem to be having trouble with --charid. I get the folowing error causing an error lock. ReferenceError: charid is not defined ReferenceError: charid is not defined at _.each._.each._.chain.map._.chain.filter.charIDList (apiscript.js:1964:41) at eval (eval at (/home/node/d20-api-server/api.js:146:34), :65:16) at Object.publish (eval at (/home/node/d20-api-server/api.js:146:34), :70:8) at /home/node/d20-api-server/api.js:1489:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400 The macros i am trying to get to work are as follows, but i get errors of the sort from any command using --charid !setattr --charid @{character_id} --mod --repeating_item_-<An ID>_qty|-1