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

[BUG][API][DESIGN] The GM's default speaking as breaks msg.who

February 28 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'm working on a complete overhaul of a couple of my scripts and was redoing how they handle sending messages to players. I was going to simply use msg.who to have the script reply directly to the player/GM sending the message, but I've run into a snag that seems like a poor design decision rather than a true bug.

The GM's default speaking as option is set to:
GM's display name + " (GM)"
Which would be "Scott C. (GM)" for me.

The problem is that when the GM sends a message as themselves, the api logs the msg.who as "Scott C. (GM)", but my in game display name is just "Scott C."

This causes the following code to log a chat error to the API console log and not send a message:
on('chat:message',(msg)=>{
	sendChat('Chat tester','/w "'+msg.who+'" This message is a test.');
}
Error Generated:
{"who":"error","type":"error","content":"Unable to find a player or character with name: Scott C. (GM)"}
It seems like if a name is an option in the speaking-as dropdown selection, it should also be a valid whisper target.

-Scott
February 28 (7 years ago)
I ran into that issue in the past and would just use a .replace(" (GM)", "") before sending any messages out.
February 28 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Aye, thought about that. There are various ways around it, but my point was more that it seems like an odd design choice to have it be that way.
March 01 (7 years ago)
Lithl
Pro
Sheet Author
API Scripter
function idToDisplayName(id) {
return getObj('player', id).get('displayname'); } on('chat:message', function(msg) {
sendChat('Chat tester', `/w "${idToDisplayName(msg.playerid)}" This message is a test.`);
});
This solution will always send the whisper to the player, instead of to a character, but outside of multiple players being assigned to a single character (eg, with characters representing languages), that's hardly an issue. In fact, for a script which whispers back to whoever triggered it, that's probably a bonus