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

Changing an attribute with setattr and then echoing the value in chat is not accurate

1524009853

Edited 1524010389
So I want to have a macro that decrements a value and then says what the new value is in the chat. All of my attempts so far result in setattr doing its thing and then the "echo" to chat showing the value from before setattr. My first attempt was simple: !setattr --sel --ccp|[[@{selected|ccp}-1]] @{selected|character_name} spent 1 Character Creation Point and has @{selected|ccp} remaining. I figured setattr was asynchronous and so I introduced a delay using the Store Commands script, or at least I think I did. @{selected|ccp} !setattr --sel --ccp|[[@{selected|ccp}-1]] !store -1000 @{selected|character_name} spent 1 Character Creation Point and has @{selected|ccp} remaining. !run !clearstore But even with the delay it was giving me the pre-setattr value, and even if I jacked the delay up to 3000ms. I've tried to google this several different ways but no luck.  What's the best practice here?
1524011619

Edited 1524011819
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
attribute calls are resolved at the time they are sent to chat, so assuming that your ccp attribute on character Varkus started at 5, here's what the API sees when it gets the message: First Code !setattr --sel --ccp|[[5-1]] Varkus spent 1 Character Creation Point and has 5 remaining. Second Code 5 !setattr --sel --ccp|[[5-1]] !store -1000 Varkus spent 1 Character Creation Point and has 5 remaining. !run !clearstore The problem isn't that chatSetAttr is asynchronous (it can be depending on how you have it set up). It's that your attribute calls evaluate before any script sees the message let alone is fired. Why not just do this: !setattr --sel --ccp|[[5-1]] @{selected|character_name} spent 1 Character Creation Point and has [[5-1]] remaining. EDIT: If you don't want the inline roll formatting around the amount left, and just want it to look like normal text, you can do this: !setattr --sel --ccp|[[5-1]] @{selected|character_name} spent 1 Character Creation Point and has[ ]([[)[[5-1]] remaining.
Yeah, I ended up just "doing the math twice". I'm ok with the roll formatting as it makes the result stand out visually.  I think I was making it too complicated, as is my wont. !setattr --sel --ccp|[[@{selected|ccp}-1]] @{selected|character_name} spent 1 Character Creation Point and has [[@{selected|ccp}-1]] remaining.
1524018090
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Scott C. said: EDIT: If you don't want the inline roll formatting around the amount left, and just want it to look like normal text, you can do this: !setattr --sel --ccp|[[5-1]] @{selected|character_name} spent 1 Character Creation Point and has[ ]([[)[[5-1]] remaining. Hmm, can you explain what's going on in that last line. I've scratched my head often trying to achieve that effect.
1524019347

Edited 1524019529
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
keithcurtis said: Scott C. said: EDIT: If you don't want the inline roll formatting around the amount left, and just want it to look like normal text, you can do this: !setattr --sel --ccp|[[5-1]] @{selected|character_name} spent 1 Character Creation Point and has[ ]([[)[[5-1]] remaining. Hmm, can you explain what's going on in that last line. I've scratched my head often trying to achieve that effect. Sure, all it is is a blank url markdown to hide the extra leading inline roll brackets. I actually posted something based on this in the stupid tricks thread for forcing a roll template to display as if there was a crit. As for why it works, I don't know the coding/design reason behind it exactly, but if you put too many leading pairs of inline roll brackets, all rolls after that point on the line (or in the roll template) will appear as regular text with no hover tooltip. Typically I would hide the extra leading brackets in the space between two roll template fields or between the ! and 
 in an api command button, but since this macro is pretty barebones, those aren't options.
1524031184
Jakob
Sheet Author
API Scripter
You can also use ChatSetAttrs output functions for this (slightly overkill, but ...): !modattr {{   --sel   --ccp|-1   --fb-public   --fb-from Moonpile   --fb-header   --fb-content _CHARNAME_ spent 1 Character Creation Point and has _TCUR0_ remaining. }}
Jakob, I read your documentation on ChatSetAttrs a while back and never saw anything about !modattr.  Is that just an alias to !setattr? Thanks for pointing out the feedback options!  I probably had glossed over that before!
1524122700
Jakob
Sheet Author
API Scripter
!modattr is an alias for !setattr --mod.
Yeah, I saw that in there upon re-reading the documentation more closely.  Thanks!  I wasn't even using the --mod option and that's what I really want instead of something like: !setattr --sel --ccp|[[@{selected|ccp}-1]]