
SelectManager Current Version (and link): 0.0.4 (Currently in my personal repo, pending a submission to the one-click.) This script is a joint project between myself and TheAaron bringing added functionality to scripts (or maybe returning functionality). Concept Abstract : Preserve the selected ( v0.0.4 EDIT : and who and playerid) property of the message object from any user-generated api call so it is available to any other script called *from* the API. Normally, API-generated script calls do NOT have a selected property (or it is undefined), and the other properties get reset. Example : Bob has a script called Burninate . Burninate does a certain amount of work and then it can, optionally, fire off another script if you supply the command line. Bob would like to fire off the script GoodJorb , but GoodJorb relies on having tokens selected at the time you make the call. By using Burninate to call GoodJorb , the resulting message object that reaches GoodJorb does not contain the selected tokens. By including SelectManager in the installed scripts and by a small change to GoodJorb (which, hopefully, all scripters will take to including as a best practice going forward), the selected tokens that reach Burninate (as a user-generated call) will be available to GoodJorb , even though it will be started from the API. Syntax There is no syntax to implement for the user. You will not call this script directly. Can't get easier than that, can it? Just install it so that your other scripts can be upgraded to use it. Scripters might eventually update their own scripts, but you can update them yourself if you want. Read on to find out how... Implementing for Other Scripts (API-Proofing) -- Suggested Best Practice Going forward, as a "coding best practice", we'd suggest scripters implement one of 2 paths for utilizing SelectManager. This will "api-proof" your script against the possibility that another script might call yours. Option 1: Require SelectManager as a script dependency As of v0.0.4, SelectManager is on its way to the one-click. Once it arrives, you will be able to designate your script as having a dependency on SelectManager. Once that is the case, you can access the library directly: msg.who = SelectManager.GetWho(); msg.playerid = SelectManager.GetPlayerID(); msg.selected = SelectManager.GetSelected(); Option 2: Make it Optional This example show how to implement the GetSelected() function off of the SelectManager library. You can extrapolate from these a similar process for implementing any of the other functions that you might need from SelectManager. FIRST , add the following 2 lines to the outer scope of each script to api-proof: let getSelected = () => [];
on('ready', () => { if(undefined !== typeof SelectManager) getSelected = () => SelectManager.GetSelected(); });
SECOND , add this line in whatever code handles the on('chat:message') event, directly after the test of whether the script should answer the api call. Be sure to replace 'msg' with whatever name the script is using for the message object received by the handler (examples will follow, below): if('API' === msg .playerid) msg .selected = getSelected(); Note for Scripters ("why" a best practice) SelectManager is fairly simple to reverse engineer and see how it works: it listens to all api calls, detects those that are user-generated, and tracks the selected property of the message object in the state variable. Any and/or all scripts could do this independently, but to avoid needlessly bloating the state variable and to minimize the overhead of many scripts taking the same action, we suggest we all standardize around this implementation. Then, as the interface is enhanced with future development, you will be able to take advantage of it. Then we just encourage users to install SelectManager with any game, no matter the other scripts that will be installed, just as a way to extend the base Roll20 functionality. Change Log: Version 0.0.3 - Initial Release Version 0.0.4 (link) - Added GetWho() and GetPlayerID()