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

ChatSetAttr changing to a query

1659724309
I'm new to working with API, but I'm trying to change all the character sheets in one of my games to better meet my game style. What I need to do is set an attribute to a roll query. Like this: !setattr --sel --query_roll_bonus|?{@{text_roll_bonus}|0} But when I try it as is I get:  TypeError: Cannot read properties of undefined (reading 'substring') When I change the attribute to specify @{selected|text_roll_bonus} I get the roll query popup, and the attribute changes to whatever output I have. I think there's a way to escape the query, but I'm not sure how?
1659725214
I think you simply need to add the --replace option to your macro, so it would be this: !setattr --sel --replace --query_roll_bonus|;{'{text_roll_bonus}|0} <a href="https://github.com/Roll20/roll20-api-scripts/blob/master/ChatSetAttr/README.md" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/blob/master/ChatSetAttr/README.md</a> --replace will replace the characters &lt; , &gt; , ~ , ; , and ` by the characters [,],-,?, and @ in attribute values. This is useful when you do not want roll20 to evaluate your expression in chat before it is parsed by the script. Alternatively, you can use \lbrak, \rbrak, \n, \at, and \ques to create [, ], a newline, @, and ?. Alternatively you could replace them yourself like this: !setattr --sel --query_roll_bonus|\ques{\at{text_roll_bonus}|0}
1659725736
Thanks, but that didn't seem to fix it. The attribute is now: \ques{\at{text_roll_bonus} / 0} &nbsp; and so I don't get the query :\
1659726509
Ah a little later down in the README : If you want to use the '|' or '#' characters inside an attribute value, you may escape them with a backslash: use '|' or '#' instead. And I copied-and-pasted without including the --replace option, which you still need for the \ques and \at replacements, and the | needs to be escaped with a backslash.&nbsp;&nbsp; Which means that it should be:&nbsp; !setattr --sel --replace --query_roll_bonus|\ques{\at{text_roll_bonus}\|0} I just tested it out and it appears to work.
1659728156
Thank you! That did it! I had tried that all individually, but I kept missing the "--replace"