
https://gist.github.com/Parmeisan/9822139
What is the purpose of this script?
To allow you to call a macro and send it variables, if you know them. You can do it from the chat, or from another macro. You can call several in one place. You can nest your macro calls and send them as parameters to each other.Why would you want that?
It greatly expands the capabilities and ease of maintenance of macros. It's really easy to write "high level" macros that are intended to be sent to other macros, and all the output from each of them is kept and used.Examples - preface:
In my campaign, which is in the Savage Worlds system, the default roll for Wildcards - or players - is 1 of a certain type of die, depending on your skill level (d4, d6, d8, etc) along with a d6, then both dice can explode, and then you take the higher of the two. Easy enough to write a macro for that, and for the mook rolls. And another for determining whether or not it succeeds by whether it surpasses another value (usually but not always 4). (And noting every time it passes by another 4, which is called a "raise" and which is also important to know). You can do that already, but I reference them below, so here they are:#WC-Roll: ?{Skill} (1d?{Die Type}): [[{1d6!,1d?{Die Type}!}kh1]]
#M-Roll: ?{Skill} (1d?{Die Type}): [[1d?{Die Type}!]]
#Success: [[floor({{?{Roll}-?{Target}}/4}+1)]] Successes
Example 1:
Now I could write a macro each for Fight, Notice, Stealth, etc etc that used both of these, but I would have to group it all together so that it loses the nice output, and it would have to all be repeated for every skill, and if I noticed something that needed fixing, I'd have to fix it everywhere. I like these ones better:#Fight: #Success(#WC-Roll(Fighting,@{selected|Fighting}),@{target|Parry})
#Skill: #Success(#WC-Roll(?{Skill},?{Die}),?{Target})
#M-Skill: #Success(#M-Roll(?{Skill},?{Die}),?{Target})
#Notice: #Skill(Notice,6,4)
#Climb: #Skill(Climb,6,4)
#Stealth: #WC-Roll(Stealth,8)
(I opted to define most of the skills on the Character instead of in general macros, since it's now just as easy to upkeep the skill value from the Ability list as it would have been to upkeep it on the Attributes, and this keeps my Ability lists shorter. There would be pros and cons to doing it the other way, but both are viable.) (Also, Stealth is opposed, and often some time after rolling it, so I don't try to count successes on it.)
If I click on a token and hit "Fight" and click on another, the output is this:
Rendelle (GM): #Success(#WC-Roll(Fighting,8),5)
#WC-Roll: Fighting (1d8): [4]
#Success: [0] Successes
Example 2:
Now imagine one of my characters is hiding and has rolled Stealth. I have 2 mooks and a wildcard who have a chance to notice. I haven't set them up as characters or anything, but I could still type directly into the chat window to get this output (the first line is what I type):Rendelle (GM): Larissa: #WC-Roll(Notice,6), Folmar: #M-Roll(Notice,4), Jaq: #M-Roll(Notice,6)
#WC-Roll: Notice (1d6): [2]
#M-Roll: Notice (1d4): [3]
#M-Roll-2: Notice (1d6): [1]
Usage:
I've shown a lot of usage examples already, but I need to point out that you CANNOT include a space after the macro name and before the bracket. If you do this, the Roll20 chat intercepts it before even sending it to my script, and there's nothing I can do to make it work.Updates & To-Do List: (Last update: March 27, 2014)
I'm sure you guys can break this in ways I've never imagined, so just let me know and try to post updates/fixes. (Note that most of the time when the API throws an error like "such and such was expected, found x instead", it's actually coming from the sendChat and is likely a problem with the set-up of your macros.)- [TODO] Unfortunately, example 2 - where multiple macros are called on one line - doesn't work with nested macros, e.g. I couldn't do the same thing with #Skill rolls. This is because ... yeah, it's kind of complicated. But it will take a lot more work to make it handle that. In the meantime, you can just do it on separate lines.
- [TODO] Whispers are not handled, by which I mean further calls don't continue to whisper.
- [TODO] I could definitely make the debug output cleaner so that it could actually be used by anyone who wants to help test.