
Stop me before I go too far; I might be replicating existing functionality. Then again, as I'm new to R20 and maybe don't know all the ways people typically use it, tell me if there is more that could be done. :-) I wanted a script that could let me modify parameters for an ability on an ad hoc basis (see below for why I wanted this). So, the implementation of this would look like: {an ability} ==> [has replaceable parts ("hooks")] {the script} ==> [has functions that process values for those hooks] Straightforward. In practice, it would look like this... take an original ability like: OriginalAbility:
!some_script --arg1:The Value --arg2:Another Value --arg3:So much value If that ability also accepted a "target" argument that would parse a list of token IDs separated either by space or by comma, you might at times need options like: !some_script --arg1:The Value --arg2:Another Value --arg3:So much value --target: @{target|Target 1|token_id} !some_script --arg1:The Value --arg2:Another Value --arg3:So much value --target: @{target|Target 1|token_id} @{target|Target 2|token_id} !some_script --arg1:The Value --arg2:Another Value --arg3:So much value --target: @{target|Target 1|token_id} @{target|Target 2|token_id} @{target|Target 3|token_id} ... Ugh. So, instead, drop a hook into that part of the Ability. In this case, I'll use "__target__" (what you use is up to you): !some_script --arg1:The Value --arg2:Another Value --arg3:So much value --target: __target__ And then write a new ability or macro with the InsertArgs script, using any/all of your hooks as arguments: !insertargs --load:OriginalAbility --__target__: [...] The InsertArgs script will take the original text of your Ability, replace the hook with the new value, and output it. In this case, since "@{target}" can't be processed from the API, the InsertArgs script "loads" the newly replaced text of the Ability into an Ability called "InsertArgs" (or creates it, if it doesn't exist), ready to be run. "But have we really accomplished anything?" I hear you say. "We've just carved out that part of the OriginalAbility command line to the new script... what have we really done?" Hold on, this is where it gets good... ...goodish... You could supply just raw text to the hooked argument to have it pass that straight through. But there are internal functions available to you to call to produce particular outputs. In this super-beta version of the script, there are two: gettargets( # ) targetsel() The targetsel() function doesn't take any arguments, but uses the tokens selected at the time the script is run. The gettargets() function takes a numeric value as an argument, and spits out that many @{target|Target #|token_id} statements to the hook. To make the gettargets() function really dynamic, feed it with an input query: !insertargs --load:OriginalAbility --__target__:gettargets( ?{Targets|1} ) (I would love to expand the list of available internal functions, but that's where my inexperience on R20 gets in the way. If there are ideas for other functions this script could do, let me know!) Code and Syntax API Call: Call it using either "!insertarg " or "!insertargs ". Arguments: Structure your arguments as " -- key :val" pairs. key: your next hook val: how to replace that hook Special Arguments: The first argument tells the script how to operate.
key: "chat" or other
val: name of Ability to operate on
The first argument's key is evaluated against "chat". If you want your finished output to go to the chat window immediately, use "chat". Anything else will tell the script to load the output into the InsertArgs ability. (Also, the internal functions know that you shouldn't send a @{target} to the chat, so they won't let you, and will instead load your output.) :-) Here is the code. All feedback is welcome, either of the "I tried it out..." sort or just as code review. EDIT: I dumped the code out to a Gist... <a href="https://gist.github.com/TimRohr22/0bd3a5f538fea0470b35ec871e479835" rel="nofollow">https://gist.github.com/TimRohr22/0bd3a5f538fea0470b35ec871e479835</a> EDIT : Newer version now in my Cauldron GitHub repo; still in pre-release beta: <a href="https://github.com/TimRohr22/Cauldron/tree/master/InsertArg" rel="nofollow">https://github.com/TimRohr22/Cauldron/tree/master/InsertArg</a> Version 0.2 Updates: -- the available functions are now independent objects. A library-style object is used to test user input against the available functions (keys), passing in the remaining arguments. Add a function, add a key to the library. -- multiple arguments can now be passed to the available functions by use of " :: " (space colon colon space) as the delimiter -- the gettargets() and targetsel() functions now accept a custom delimiter. For gettargets(), it is the second arg. For targetsel() it is the first. If it is not provided, a space is used. To get an empty delimiter, use the argument delimiter but don't supply a value.