
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(); });
if('API' === msg.playerid) msg.selected = getSelected();