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

Combining different API commands & Macros

Yo! So I have a question that I haven't manage to find an answer to that I understood. Basically, API's have their commands, and Macros have their, well macros. Sometimes we want 1 macro button to call several commands on one press, and that's where I'm at a loss. I guess this is also a Two-Part kind of question, since I'm guessing (without actually knowing) that combining several API commands is one thing, while combining API commands with Macro code is different... I guess, think, probably. (Yes I'm a complete newbie on this) Let's start simple. I have script I got from a Nick O video, that summons a Spiritual Weapon token with a flashy fx animation, the command is !spiritualWeapon . I also have a macro that calls for the Spiritual Weapon spell card. %{selected|repeating_spell-2_$16_spell} (Yes, the compendium thing is an attack, not a spell card, but I changed that so I can cast the spell with the description, and then use another macro for an Attack input for the actual swing-of-the-spiritual-weapon) . Now... what I would like, is to summon the hammer when I cast the spell. A.k.a, I click the macro, the spell is cast, the spell card pops up and if spell slot tracking is on, then a spell slot is expended... And the hammer is summoned. But I have no idea how to combine that. What I have so far is basically just the two commands, which means that the current macro I have looks like this: %{selected|repeating_spell-2_$16_spell} !spiritualWeapon So, how do I make them both trigger, when I click that macro button? The second part is pretty much "Does it work the same way with API+API command as API+Macro, and "If not, what are the differences". I guess I can add a third part as well. Like, will the combine thing work differently depending on how the macro is written, or will it still be the same. For example, how would you combine these different stuff? No need to ask why I want to combine this/that macro with that/those commands, because I won't, they are purely examples here, nothing more. My goal with these ones are simply... to learn, and understand. :) But because I'm such a newbie... eh, try to teach me in a way I would hopefully understand. :D Example 1 - Macro + API /em @{selected|token_name} rolls a [[1d20+@{selected|initiative_bonus}&{tracker}]] for initiative! !torch Example 2  - Long Macro + API + API /w gm &{template:default} {{name=Stats}}{{Armor Class= [[@{selected|ac}]]}}{{Health= Now: [[@{selected|hp}]] Max: [[@{selected|hp|max}]]}}{{Spell Save DC | Attack Bonus=  [[@{selected|spell_save_dc}]] | [[@{selected|spell_attack_bonus}]]}}{{Speed= [[@{selected|speed}]]}}{{Passive Perception= [[@{selected|passive_wisdom}]]}}{{Weight Now & Max= [[@{selected|weighttotal}]] | @{selected|weighttotal|max}[[@{selected|strength}*15}]]}}{{Standing= [[@{selected|strength}/2]] Long Jump | [[@{selected|strength}]] High Jump}}{{Running= [[@{selected|strength_mod}+3)/2]] Long Jump | [[@{selected|strength_mod}+3]] High Jump}}{{Hold Breath= [[@{selected|constitution_mod}+1]] min}}{{Rounds w/o Breath= [[@{selected|constitution_mod}]]}}{{Without Food= [[@{selected|constitution_mod}+3]] days}} !torch !spiritualWeapon Example 3  API + API + API !torch !spiritualWeapon !bump-slave [--push | --help] So, yeah. I looked at the API wiki, I've been reading forum posts, but... I'm at a loss because I didn't understand it. <3 And I want to understand so I can learn and know! :D
1595116627
The Aaron
Roll20 Production Team
API Scripter
Ok, so trying to hit your three questions one at a time: 1) Can you have multiple macros, abilities, and api commands all called in the same macro or ability (or multi line chat box entry)? Yes!&nbsp; All those places (macros, abilities, and multi line chat box) will just execute each command in the client (* caveat, see below) one after another. 2) Does it work the same way when mixing macros and macros, macros and abilities, abilities and abilities, macros and api, abilities and api, api and api? Yes! It works just the same. (*caveat, see below) 3) Are there circumstances where things will work differently based on order or other things? Yes, it's caveat time!&nbsp; &nbsp;Here are some things to know about each of those types of commands, then we'll talk about what it all means. Macros: Tied to a specific Player, only editable by them, not transferable between games (without API help) Multiline collection of commands Eats HTML Entities on edit Executed on the client, as if you typed the commands into the chat Abilities Tied to a specific Character (so you can use the Character Vault or Transmogrifier to move them) Multiline collection of commands Preserves HTML Entities on edit Executed on the client, as if you typed the commands into the chat API Commands Tied to API Scripts Single line command parsed by the API Executed on the API Server So, Macros and Abilities are very similar, and vary mainly in their accessibility, portability and obnoxiousness. (I'm not biased (Abilities Rule!!) =D)&nbsp; API Commands are completely different.&nbsp; You can really think of Abilities and Macros as each being two things an "Ability Command" that you type in chat and an "Ability Body" which is what gets executed, same for Macros. The way that chat commands work is entirely dependent on the Order of Operations: &nbsp; <a href="https://wiki.roll20.net/Dice_Reference#Order_of_Operations" rel="nofollow">https://wiki.roll20.net/Dice_Reference#Order_of_Operations</a> Basically, Ability and Macro Commands are replaced with their Ability and Macro Bodies (recursively up to 99 times each) and Attribute references are expanded to their values.&nbsp; Then Roll Queries prompt the issuer for information, Inline rolls are rolled, non-inline rolls are performed, and finally, the message is sent to chat. And here's the interesting part.&nbsp; The API does not see a message until AFTER it has been sent to chat.&nbsp; There is an implication to be aware of: If you have macros/abilities that are displaying some attribute and a script that is changing that attribute, the results of the API cannot be displayed no matter the ordering because the macro/ability expansion happens before the API ever sees it's commands. One other thing to be aware of, there is a long standing bug (yes, bug , because it didn't always work this way and got broken in an update 3-4 years ago): If you use @{target|...} anywhere in a combined set of commands (macro, ability, multiline chat), none of the selected objects are sent to the API. Other than that, everything should be just peachy.&nbsp; Probably...
1595116700
The Aaron
Roll20 Production Team
API Scripter
Side note, this: !bump-slave [--push | --help] The [ ] just means optional commands, and the | means "or", so this is saying any of these is a valid command: !bump-slave !bump-slave --push !bump-slave --help Cheers!
Oooh, that was massively informative, and I will take a look at that order of operations link, then see if i can figure out how the ability should be written to get the "cast spell" macro and "call api that summons token" to play together! We'll see how this goes. :P
Right, I found what I had done wrong in that summon macro... and, if I was a programmer I would feel pretty dumb now, but fortunately I'm a complete amateur, so I'm instead happy I realized! :D I had this, which only gave me the spellcasting. %{selected|repeating_spell-2_$16_spell} !spiritualWeapon But I should have had this instead, which did both! :D {%{selected|repeating_spell-2_$16_spell} !spiritualWeapon} ...And here I assumed there were some black magic code stuff to combine them... and all i really needed was to put them inside a pair of { }.... xD Thank you! :D
1595189515

Edited 1595189525
The Aaron
Roll20 Production Team
API Scripter
I have no idea why that makes it work, but yay! =D
No idea, but my guess is that the brain that reads the abilities (that's an ability on a char sheet, now when you mentioned the difference of a macro (collection) and the sheet abilities) just wants it to be contained together, I guess? so putting it in a {} together made it work, while just having them on two separate lines was like "erh, i can read the first line but then i'm kinda just missing out on the second one for... some reason" ... xD But... that's just a complete guess for a non -programmer who doesn't understand this at all. :D
1595353336
The Aaron
Roll20 Production Team
API Scripter
Ah, actually, if it's on a character sheet, it's a roll button.&nbsp; That's kind of like an Ability, but not precisely.&nbsp; Abilities are manually created on the Attributes and Abilities tab.
Yes those are the ones I mean, the Attributes and Abilities tab. I kinda call the whole window the Character Sheet even if it's several different pages where character sheet is just one of the, (and the others being bio &amp; info, attribs and abils, and so on.) Sooo yeah, it's the one on the attrib/abil tab. :)
1595355430
The Aaron
Roll20 Production Team
API Scripter
Ah, good.&nbsp; Yeah, totally understandable.&nbsp; I've been here since the idea of Character Sheets on Roll20 was anathema to the dev, so it's firmly a different animal in my mind when I read it. =D
Ah, well, if we really want to be technical then I was wrong and you were in fact correct. :P The window contains several tabs, and only one of them is the Character Sheet after all. I just.... clump all the tabs together and call it the Character Sheet. x)
1595356080
The Aaron
Roll20 Production Team
API Scripter
HAHAHAHA!&nbsp; Just trying to avoid confusion.&nbsp; Terminology can really cause problems when different people have different definitions. =D&nbsp; Generally, people will call that whole collection of tabs the Character, and the tab with the pretty HTML the Character Sheet.&nbsp;&nbsp;
That.... is actually way smarter... character as the whole thing, and character sheet for the sheet... Smart! I might actually adapt that :P
1595357903
The Aaron
Roll20 Production Team
API Scripter
If you think of it like a model of the physical world, the Character is kind of like "that manila folder where you keep the character sheet, print outs of what they look like, notes about their background, note cards about their special equipment, a map of their stronghold, etc..."&nbsp; =D
Exactly! :)
1595385510
GiGs
Pro
Sheet Author
API Scripter
To be p[recise, the roll20 term for the whole shebang is the Journal, with the Character Sheet being just one of three tabs in the Journal. But I dont know anyone who uses that terminology, its just more natural to use the term character sheet, which often causes confusion.
1595387353
Kraynic
Pro
Sheet Author
Especially since Journal is also the name of the tab where you find handouts and ... journals.&nbsp; But when you go to create a "journal", it is called a character in the drop down list generated by the "Add" button.
1595388387
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
When I feel the distinction needs to be made, I usually call it a "Character Journal" to distinguish it from a handout or character sheet.