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

Conditionally call API from inside a macro

I'm creating a number NPCs who have rechargeable abilities.  I wanted to create a token macro that would toggle a status on and off whether or not the ability was available, and do it automatically based upon a roll that the macro does. For example: I click the macro button. Macro rolls a 1d6 For a 1 through 5 (or whatever), it sets a token status using the TokenMod script.   !token-mod --set statusmarkers|red If it's a 6, it clears the status marker. It appears that conditionals only work with regular math, so I've tried a few other things but can't figure out how to have it actually execute the API script.  It either does nothing or spits it out as plain text...  First attempt was this: &{template:mancerroll} {{title=title}} {{c1=[[1d2]]}} {{option1=(!token-mod --set statusmarkers|!red)}} {{option2=!token-mod --set statusmarkers|!blue}} But that just ended up spitting the API command out as text.  I also tried downloading the Rollable tables and doing stuff with thatbut couldn't get that to work either. Is this feasible to do automatically, or will it require at least some manual intervention? Thanks!
1647215435

Edited 1647215754
Oosh
Sheet Author
API Scripter
It should work with an escaped line break: ?{Move Token?|Yes,Moving...
!token-mod --set top|-70|No,Not moving} You'll also need to escape anything that breaks the query, like the | pipes in the token-mod command line. Whoops, you don't have a Query in there. This won't work with optional template displays, unfortunately - the roll template will break at the first 
 since it sends a new line (required for your API call to work.... the first character of the line must be "!"). If you can rejig that to use a query it will work, but roll template display is handled by CSS - it makes the unselected {{option}} fields invisible, but the code in them is still parsed. I think a query is the only way to have multiple API calls in the one macro without breaking it.
1647216602

Edited 1647217705
So that creates a pop up, which is similar to how I've solved the problem for now (I did an inline option to click on).  Is there a way to make it automatically choose one of those choices based upon a die roll?  I want it to roll a D6.  If it's a 6, it does API call A.  if it's not a 6, it does API call B.  I'd like to be able to push one button and it handles everything without my intervention.  I don't know if this is possible. The conditional stuff I found on the wiki only seemed to work with math, they couldn't do API calls (or I was doing something wrong). Edit:  This is the macro I'm currently using. /w gm &{template:npcaction} {{name=Shadow Thrall}} {{rname=Shadow Step Recharge (5/6)}} {{description=Recharging... [[1d6]] [Success](!token-mod --set statusmarkers|=dead|-dead) [Failure](!token-mod --set statusmarkers|red)}} I don't need it to be in a template, it's just there because it pretty looking.
1647224786
David M.
Pro
API Scripter
If you're willing to try the scriptcards script, it's pretty simple (see below). Note: also requires the SelectManager script. !scriptcard {{ --#title|Shadow Step Recharge --=roll|1d6 --+Recharge Roll:|[$roll] --?[$roll] -eq 6|[ --+Result|Recharge successful! --@forselected|token-mod _set statusmarkers|red --]|[ --+Result|No recharge --@forselected|token-mod _set statusmarkers|=dead|-dead --]| }}
Exactly what I was looking for.  Thanks!