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

[Script] ChatSetAttr - set character attributes via chat messages

January 17 (8 years ago)
Is it happy dance time? Riley rolled out that change you needed. 
January 17 (8 years ago)
Jakob
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...
January 17 (8 years ago)
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. 
January 17 (8 years ago)

Edited January 17 (8 years ago)
Jakob
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.
January 18 (8 years ago)
Jakob
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.
January 19 (8 years ago)

Edited January 19 (8 years ago)
vÍnce
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?
January 19 (8 years ago)

Edited January 19 (8 years ago)
The Aaron
Pro
API Scripter
Likely this: https://app.roll20.net/forum/permalink/4514812/
and this: https://app.roll20.net/forum/permalink/4513979/
January 19 (8 years ago)
The Aaron
Pro
API Scripter
Summary:  Sheet worker checks that the source is 'player', but the source is 'api'.  
January 19 (8 years ago)
vÍnce
Pro
Sheet Author
I'm using our latest code with the changes made for the API update...
January 19 (8 years ago)
The Aaron
Pro
API Scripter
Then I've got nothing! =D
January 19 (8 years ago)
chris b.
Pro
Sheet Author
API Scripter
is it 'api' in small letters? that is what it looks for:
eventInfo.sourceType === 'api' || eventInfo.sourceType === 'player'
I changed everything to the above.
January 19 (8 years ago)
vÍnce
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?  
January 19 (8 years ago)
Jakob
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'.
January 19 (8 years ago)

Edited January 19 (8 years ago)
vÍnce
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.
January 19 (8 years ago)
Jakob
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 ;).
January 19 (8 years ago)
vÍnce
Pro
Sheet Author
Sounds good.  Thanks
January 19 (8 years ago)

Edited January 19 (8 years ago)
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!
January 19 (8 years ago)
Jakob
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?
January 19 (8 years ago)

Edited January 19 (8 years ago)
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
January 19 (8 years ago)
Jakob
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.
January 19 (8 years ago)
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.
January 19 (8 years ago)
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?
January 19 (8 years ago)
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!
January 19 (8 years ago)
The Aaron
Pro
API Scripter
Ah, for repeating, that's unlikely to work. =/  I'll have to experiment with that.
January 19 (8 years ago)
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.

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 barx_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.
January 20 (8 years ago)
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.
January 25 (8 years ago)
Jakob
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?
January 25 (8 years ago)
vÍnce
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.
January 25 (8 years ago)
Jakob
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.
January 25 (8 years ago)
It has  been lightning fast for me on shaped sheet as well. Flawless
January 25 (8 years ago)
vÍnce
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.
January 26 (8 years ago)

Edited January 26 (8 years ago)
vÍnce
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
January 26 (8 years ago)
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.
January 26 (8 years ago)

Edited January 26 (8 years ago)
vÍnce
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)"
January 26 (8 years ago)
The Aaron
Pro
API Scripter
You'll need to add it before TAS.
January 26 (8 years ago)
vÍnce
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.
January 26 (8 years ago)
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?
January 26 (8 years ago)
vÍnce
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

January 26 (8 years ago)
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.
January 26 (8 years ago)
vÍnce
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?
January 26 (8 years ago)
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})]]

January 26 (8 years ago)

Edited January 26 (8 years ago)
vÍnce
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})]]
January 26 (8 years ago)
The Aaron
Pro
API Scripter
Hey, I can't do everything for you... =D
January 26 (8 years ago)
vÍnce
Pro
Sheet Author

The Aaron said:

Hey, I can't do everything for you... =D
Who says?  You must have been talking to Stephen...

January 26 (8 years ago)
The Aaron
Pro
API Scripter
Not in hours! =D
January 26 (8 years ago)
Jakob
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.
January 26 (8 years ago)
The Aaron
Pro
API Scripter
Ah yeah, that 1* bit isn't even needed...  Man, I'm getting more "human" all the time!
January 26 (8 years ago)
vÍnce
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... ;-)
January 27 (8 years ago)
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