Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

sendChat whispered to a *character* name results in no output

1605279255
David M.
Pro
API Scripter
I'm currently modifying one of my scripts (!radar) to allow being called from another script (powercards). The original version was whispering output to the displayName of the player calling the script. who = getObj('player',msg.playerid).get('_displayname'); sendChat(scriptName, `/w "${who}" `+ 'Some output string');    //this works Since msg.playerid can now be "API", this will obviously not work for that case. So, I was thinking to instead just whisper the output to the character represented by the selected token (or in the case of being called by another script, the token with an id passed as an argument to the radar script). This should allow for whomever controls the character to receive the whispered output, in my understanding. My problem seems to be that whispering to a character is not working for me from a sendChat. For example, this does nothing when "who" equals a character named "Cleric". sendChat(scriptName, `/w "${who}" `+ 'Test'); No output. When I log the sendChat output string, I get "/w Cleric Test", i.e. log(`/w "${who}" `+ 'Test')  // equals "/w Cleric Test" in the console log When I copy the logged string "/w Cleric Test" directly into the chat window, it outputs correctly. The "Cleric" character is controlled by All Players for this test scenario.  Any ideas what is happening here?
1605284947
The Aaron
Roll20 Production Team
API Scripter
Hmm.  The best way to test is with a second account.  There may be something odd going on, but that looks like it should work barring any sort of issues in the unseen code.  Verify you're whispering to the character name and not the token name.  Try adding explicit players to it rather than "all" and see if that makes a difference.  Worst case, you could extract the list of actual players and whisper to them individually, and just post public for the special case of "all". Helpful functions: This is what I use for getting "who".  In the case of an API call, the getObj() will return undefined, the || will sub the json object, and the get call will return 'API' to be assigned in who: let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); Here's a function for getting the controlled by list for a given token.  It handles if the token represents a character and returns the applicable list as an array, which is a convenient object to check for any controllers with length: const playerControllers = (obj) => { if('' !== obj.get('represents') ) { return (getObj('character',obj.get('represents')) || {get: function(){return '';} } ) .get('controlledby').split(/,/) .filter(s=>s.length); } return obj.get('controlledby') .split(/,/) .filter(s=>s.length); };
1605291461

Edited 1605291920
David M.
Pro
API Scripter
Ah, it was the "All Players" in the character's "controlled by" property that was the problem! Explicitly adding the player names allows it to work as intended. To guard against this api quirk in the future, I suppose I could check the character's controlled by property and if "all" -> do a findObjs to get a list of all players and just sendChat to each.   Anyway, mystery solved, thanks for the help! EDIT - nm that last bit. I re-read your reply, and a public post for controlled by "all" would be much easier :)
1605291673
The Aaron
Roll20 Production Team
API Scripter
No problem!
1605304719
timmaugh
Pro
API Scripter
I was dealing with the exact same problem with my DiscreteWhisper script. Having "All Players" in the "Can Be Controlled By" list lets you whisper AS that character, but you don't receive any of the whispers directed TO that character.
1605305279
The Aaron
Roll20 Production Team
API Scripter
Ah, you're right.  Even in the chat, that's the case.  You will, as the whisperer, see your chat whisper message, but others will not receive it.  I just confirmed this.