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

Separating out roll queries

1487604555

Edited 1487606727
Roll20 macro language is not exactly a paragon of clarity. Here's a tip for those instances where you're creating a macro (or ability) and roll queries threaten to overwhelm your ability to parse the macro in your head. First of all, "!" is not actually a trigger for API scripts. "!" means "don't send anything on this line into the chat box." API script commands commonly start with "!" because you usually don't want to see the command itself appear in the chat. Next, it is, I feel, a somewhat underappreciated fact that when you want to use the result of a roll query multiple times in a single macro, you only need to specify any arguments for the roll query once. Any other instances can just have the name of the roll query. Combine these two things, and you realize you can put all the roll queries at the beginning of a macro, hidden from the chat by "!", and then only use the name-only versions in the actually displayed part of the macro. Put the roll queries in the order you want them asked of the user. Here's a somewhat silly example. It also takes advantage of the fact that you can close a roll template element on the following line. (I can't get it to post as code. The entire message turns into code. Sorry.) ! ?{Range| Point Blank, +0 | Short, -1 | Medium, -2 | Long, -4 | Extreme, -8} ! ?{Target Size| Tiny, -2 | Small, -1 | Medium, +0 | Large, +1 | Huge, +2} ! ?{Damage| Weak, 1d6 | Average, 2d6 | Strong, 3d6} ! ?{Damage Modifier| -1 | +0 | +1} ! &{template:default} {{name=Somewhat Silly Example }} {{Range Modifier=?{Range} }} {{Target Size=?{Target Size} }} {{Damage Modifier=?{Damage Modifier} }} {{Chance to hit=[[ 10 [base score] ?{Range} [range] ?{Target Size} [size] ]] }} {{Roll=[[ 1d20 [roll] + ?{Damage Modifier} [damage modifier] ]] }} {{Damage if hit=[[ ?{Damage} ]] }}
1487606760
Ziechael
Forum Champion
Sheet Author
API Scripter
That is a really interesting and useful tool for an organised macro, nice write up. also, fixed your code box woes for you...
This is awesome! I didn't realize that roll templates can be spaces on separate lines, now I need to go back through all of my macros because this was a huge hindrance/pet peeve.
Ziechael said: also, fixed your code box woes for you... Thanks!
1487618824
Lithl
Pro
Sheet Author
API Scripter
David T. said: First of all, "!" is not actually a trigger for API scripts. "!" means "don't send anything on this line into the chat box." API script commands commonly start with "!" because you usually don't want to see the command itself appear in the chat. No, a line starting with "!" is interpreted as an API command. There's a reason why an API script with a chat message handler will receive such a message as having the message type "api". API commands don't automatically have their contents sent to the chat, and there is nothing to require an existing script to consume any given command, and that  is what you are leveraging here. An API command with no script to interpret it (whether the campaign is capable of having API scripts or not) will simply do nothing... but the macro system will still process roll queries which were in those commands.
Macros are starting to get as arcane in their construction as they were in MapTool when they started adding pseudo-javascript years ago, lol.