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

Call macros within API and use API variables in Macro?

1519995554

Edited 1519996768
Missingquery
Pro
Sheet Author
API Scripter
I am attempting to make a command that first has the user select their token, and when run, displays a dropdown list of abilities on the character sheet, along with an "execute" button, which will then perform operations with the given option. However, I cannot directly reference said abilities using typical macro methods, as they need to be logically filtered from others in such a way that can only be done in the API (more specifically, searching for a specific string within the "action text" of the ability). So what I want to know is- can you call an API command with a macro , pass variables from of said command into another macro, then call it? Is there a better way to accomplish this task than what I have laid out? Edit: An additional unrelated question: is it possible to access the turn tracker from the API and get the assigned value of the tokens within the turn tracker in any way?
Marth Lowell said: I am attempting to make a command that first has the user select their token, and when run, displays a dropdown list of abilities on the character sheet, along with an "execute" button, which will then perform operations with the given option. The API could be used to display a display a button that when clicked queries the user for an ability. Essentially combining these two criteria into one. However, I cannot directly reference said abilities using typical macro methods, as they need to be logically filtered from others in such a way that can only be done in the API (more specifically, searching for a specific string within the "action text" of the ability). Easily handled by API and string parsing So what I want to know is- can you call an API command with a macro , pass variables from of said command into another macro , then call it? What do you mean by the above? Can you give an example? An additional unrelated question: is it possible to access the turn tracker from the API and get the assigned value of the tokens within the turn tracker in any way? Absolutely! The turn tracker contains the token ID for the token. This ID can be used to find the token object which can contain the character the token represents; assuming that the token has the Represents  field set. Otherwise the token still holds the information of the bars, auras, vision, notes, etc.
1520025496
The Aaron
Pro
API Scripter
Macros are just a collection of chat commands, so anything you can put in chat, you can put in a macro, including api commands.  Character Abilities (often incorrectly called Macros) are very similar, they are a collection of chat commands, but you can omit the character name when inside them as it is assumed to be the character the ability is attached to. The API can load the list of chat commands from either a macro or a character ability, and issue them to the chat with the sendChat() command.  HOWEVER, there are a few caveats to getting it to work: In the case of a character ability, you would need to parse all the @{} references and replace them with fully qualified versions including the character's name since you won't be executing them in the context of the character.  That looks something like this: let text = ability.get('action').replace(/@\{([^|]*?|[^|]*?\|max|[^|]*?\|current)\}/g, '@{'+(character.get('name'))+'|$1}'); In both cases, @{selected} and @{target} won't work.  You'll either have to make sure those aren't used, or provide some sort of intermediate query to the executing player where by they click a button and are prompted for those things. 
1520274214
Missingquery
Pro
Sheet Author
API Scripter
That works, thanks! Though with the turn tracker thing, I was wondering if there's any way to specifically access the value of turn counter objects, as well as possibly execute an API script when a turn counter object reaches the top of the turn order? The last one isn't too much of a priority, but it would still be neat if that were the case.
1520276205
The Aaron
Pro
API Scripter
Yeah.&nbsp; The turn order is stored in the Campaign()'s turnorder property.&nbsp; You can get it from Campaign().get('turnorder').&nbsp; It's a JSON string, so you'll need to parse it with JSON.parse().&nbsp; It can be empty, so using a construct like: let turnorder = JSON.parse(Campaign().get('turnorder')||[]; will always give you a valid result. You can also get an event when it changes: const Somefunction = (obj,prev)=&gt;{ // do stuff with current value in obj, which will be identical to the return from Campaign() in this case // do stuff with previous value in prev, which is a plain javascript object with properties like the Campaign object }; on('change:campaign:turnorder',Somefunction); and just parse the data for who's turn it is.&nbsp; Be sure to check the current and previous first turn to make sure it actually changed.&nbsp; You can look at my TurnMarker1 script for some (not well written but fairly simple) examples: <a href="https://github.com/shdwjk/Roll20API/blob/master/Tu" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Tu</a>...