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

Two API commands in one macro

1528545901
Laurent
Pro
Sheet Author
API Scripter
Is there a known issue or precautions when writing a macro that calls two API commands? I tried macros that look like !command1 !command2 and sometimes it seems to work, but most of the time not. Does it come from the scripts?
1528548371
Ziechael
Forum Champion
Sheet Author
API Scripter
I regularly run multiple API commands from one macro, most of my attacks/spells use a powercard + tokenmod + chatsetattr + a custom sound effects script. As long as your commands are on new lines you shouldn't be finding any issues, might be worth posting an example of one of your failures and the scripts it is calling so the community can advise further?
1528617291
Laurent
Pro
Sheet Author
API Scripter
Thanks Ziechael, it already helps a lot to know that it works for others. I think that helped me nail down the issue: I was sending the macro through API command button. That was after expanding the macro, and I suppose the issue is with API command buttons with more than one API command.Maybe someone knows how to execute 2 API commands pressing one button?
1528634413
The Aaron
Pro
API Scripter
Probably you’d need to html encode the Macro call to prevent it from being expanded when the button is created and let it get expanded when the button is pressed: [do thing](!
#MacroName)
1528636522
Laurent
Pro
Sheet Author
API Scripter
Yes, that would work, but I need to dynamically modify some arguments to the API command calls in the macro. Maybe I could create a temporary macro...
1528637261
The Aaron
Pro
API Scripter
Hmm... I guess just let us know where we can help. =D Dynamically adjusting the arguments to both api commands wouldn't really be possible, unless you're talking about things like @{selected}.  You could append arguments to the last API command in the macro by following the macro with them.
1528703112
Laurent
Pro
Sheet Author
API Scripter
The Aaron said: Hmm... I guess just let us know where we can help. =D Dynamically adjusting the arguments to both api commands wouldn't really be possible, unless you're talking about things like @{selected}.  You could append arguments to the last API command in the macro by following the macro with them. The first help I was  looking for was confirmation of the fact that it's not possible to call two API commands from one button, unless using macros. Then, assuming this is the case, here is the problem I'd like to solve: I have a macro, containing possibly more than one line of API commands, and each such command may contain references to the token selected when processing that macro. Each line may look like the following: !cof-attack @{selected|token_id} @{target|token_id} 1 --psave CON [[@{selected|INT}+10]] When I have only one such line, I replace all @{selected| stuff by their values, and create my button so that when pressing the button, it behaves as if the right token were selected. The issue is that replacement doesn't seem to be an option when the macro contains more than one API command.  Here are my possible solutions so far: Add an argument at the end of the macro, but that would only be passed to the last API command Create a new macro containing the modified macro, and delete the macro when it is not needed anymore. The issue with that approach is first to determine when the macro is not needed anymore, and then when it is removed, if someone presses the button nonetheless, it will be ugly.  So, I'm looking for better ideas...