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

Simple ChatSetAttr problem from a n00b

Hi, I'm using a system that is not integrated in Roll20 (Corporation RPG) and am trying to write some quick macros to help with rolls. In this system a roll is 2d10 and you must roll equal or under your AT(action total), and the difference with which you succeeded (or failed) is called XS. For example roll Agility + Close Combat with an AT of 14. Player rolls 2d10, results 6 and 2 for a total of 8. The XS would be 6. In some circumstances, this XS is applied to the damage roll. I need a way to store this simple variable when the attack is rolled so that it is added to the damage. For the moment I have a simple macro without any API scripts that asks for the AT when players click the attack button, and displays the XS in chat, and then another macro for damage that requires the player to manually input said XS. I'm trying to use setattr on an empty attribute i called atkxs so that when the attack roll is made, the XS is stored and then can be used automatically on the damage roll. I need the original attack roll to both store the XS and be displayed normally so that we can see the dice rolls and check for critical hits(manually, I'm not looking for crit integration right away). I tried a couple of things but it seems setattr can change the value of my atkxs attribute but not use that new value in the same macro. I nested the roll inside the setattr like that: !setattr --sel --silent --atkxs|[[@{melee at} + ?{Modifier|0} - 2d10cs1cf10]]. This works fine for storing the value, but it doesnt display the roll in chat, which i need in order to check for crits. When I tried to put that !setattr line inside the template macro I have for the attack, it displays the whole line as text and shows the roll but doesn't store the value on my atkxs attribute. &{template:default} {{name=@{name} @{melee weapon} Attack}} {{Excess: !setattr --sel --silent --atkxs|[[@{melee at} + ?{Modifier|0} - 2d10cs1cf10]] = [Roll Damage](~meldmg)}} How do I get this to both display the roll results as usual but also store the same result in my atkxs attribute? Thank you very much, I'm trying to awaken my long lost basic programming skills (did a little bit in high school, enjoyed it very much).
1624549726

Edited 1624549746
GiGs
Pro
Sheet Author
API Scripter
I tried a couple of things but it seems setattr can change the value of my atkxs attribute but not use that new value in the same macro. This isnt a chatsetattr problem, its a roll20 problem. when a roll20 macro runs, it grabs any referenced attributes at the instant it runs, and uses those values throughout the macro. If chatsetattr changes the attribute, you can't use the changed value, because roll20 has already grabbed the value at the start of the macro. Check out the roll20 Order of operations There are ways around it, but they can be convoluted.
1624549960
GiGs
Pro
Sheet Author
API Scripter
There's a trick called Reusing Rolls which you might be able to use. &{template:default} {{name=@{name} @{melee weapon} Attack}} [[ [[@{melee at} + ?{Modifier|0} - 2d10cs1cf10]] +1d10]] {{Excess= $[[0]]}} {{Damage (if hit)=$[[1]]}} I don't know what your damage roll is so I just used d10 for sake of example.
1624550582

Edited 1624555276
timmaugh
Pro
API Scripter
First, you can nest your rolls and then extract the information later: [[@{melee at} + ?{Modifier|0} - [[2d10cs1cf10]]]] Roll $[[0]] will be the 2d10cs1f10. Roll $[[1]] will be the outer roll, referencing the combination of all of those factors. That said, you need the roll to be used in your output and in the setattr call. For that, you'll want an API. Might I suggest Plugger,  SelectManager ,   and ZeroFrame (from the Meta Toolbox; all are available in the one-click): !&{template:default} {{name=@{name} @{melee weapon} Attack}} {&eval}!setattr --sel --silent --atkxs|$[[1]].value{&/eval}{{Excess=[[@{melee at} + ?{Modifier|0} - [[2d10cs1cf10]]]]}}{{Roll=$[[0]]}}{&simple} That should give you the data on the inner roll (which is the 0th roll computed), the XS as the fully computed roll, and it should pass the value of the XS roll (the 0-based-1st roll computed) to the setattr command. Plugger - runs the setattr command as a plug-in SelectManager - returns the selected token to ChatSetAttr ZeroFrame - unpacks the inline roll (.value), initiates meta-processing, outputs a simple message containing the templated information Note 1 : with this becoming an API generated message, you will lose the animated dice, if that was important. I'm working on a way to recapture that, but this should get you where you want to go. Note 2 : I left off the chat button, as I wasn't sure what it did or if it replicated any part of what I did. Plus, leaving it off makes the example perhaps more clear.
Thank you for your quick and clear answers! I'm at work right now but I'll check this out in detail tonight. I really appreciate it!