timmaugh said: Kurt J. said: GiGs said: Alternatively, just let me know what i need to change in MEGS to work with scriptcards. I think the only thing that would need to change is in this function: const getSender = msg => {
const character = findObjs({ type: 'character', name: msg.who })[0],
player = getObj('player', msg.playerid);
if (character) return 'character|'+character.id;
else return 'player|'+player.id;
}; When using sendChat, the SpeakingAs parameter fills in msg.who, but msg.playerid will always be "API" (I haven't found a way to change that). ScriptCards (and powercards) just pass along whatever they got for msg.who so if I'm reading things right, the only time the crash indicated above would happen is when the GM (who's msg.who value doesn't equal a character name) runs something that calls !megs via the API. In that case the character lookup will fail by name (for example, my msg.who is "Kurt J (GM)" which isn't a valid character name) and the script will try looking up a player by ID, which will also result in undefined since playerid will be API, which isn't a valid player. Alternatively, you could implement SelectManager for any script that might expect to be called by another API. I just updated SelectManager to also store the msg.who and msg.playerid properties, so now it tracks all of the items that are typically changed when a message goes through an API call. If you have your script declared as dependent on SelectManager, you could use it directly: msg.who = SelectManager.GetWho(); Otherwise, if you left it optional (until SelectManager gets into the one-click): let getWho = () => {}; on('ready', () => { if(undefined !== typeof SelectManager) getWho = () => SelectManager.GetWho (); });
// ...
// after making sure this script should catch the message msg.who = getWho(); I'm headed over to update the script thread with the new access, then I'll submit it to the one-click. Should hopefully make it in next week. Tim - I didn't know that SelectManager existed and followed the link to review and implement. I did the following: 1) added SelectManager to my active scripts 2) added the 3 lines of code (referenced in option 2) to three different API functions (ScriptCards, StatusMarkers, and ChatSetAttr). The ChatSetAttr function has syntax for apply changes to the currently selected token ScriptCards version: '--@modbattr|_sel _HP|[$Heal]' This code wasn't working previously, with an error message stating that no Token was selected. It now works - Thank You! I'm still a little confused around how to implement your Option 1, and the comments in the !ScriptCards forum (2/4/21 @12:31) you are making to improve ScriptManager.