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] Scripts parse chat messages sent by other scripts...

1390943503
Chad
Sheet Author
Okay, I've been chasing this little bug for quite a while. It looks like scripts parse chat messages sent by other scripts (on(chat:message) fires when another script sends something). From what I can tell, this sometimes results in undesirable behavior, as well as scripts which are flagged as slow running, when in fact they haven't done anything yet.
1390946537

Edited 1390946704
DXWarlock
Sheet Author
API Scripter
Are you checking to see if the chat being sent is the one each script is expecting? Sounds like it has no check to make sure the command is the right one. Like this is the one I've been using, and it works well: on("chat:message", function(msg) { var cmdName = "!command "; if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) { (do stuff here) } } This way only if its an ! command, and its the !command itself, will it continue, otherwise it does nothing.
1390946848
Chad
Sheet Author
Oh yes, I check all the time. And I usually do several checks within the on message to make sure it stays as efficient as possible. The point is, it's still firing the "on message" of every script when every other script in the game sends a text. And it also seems to be firing the "on message" when it sends a message itself. And it looks like it may be firing it for older messages in the chat too. In other words, it isn't too long before on message is firing many many times whenever the sandbox is loaded. The bug isn't in making sure its the right message. The point is that the event is firing so many times that the event itself causes a delay.
1390947043

Edited 1390947296
DXWarlock
Sheet Author
API Scripter
Hmm haven't had that happen, I did earlier forget to check if it was the right command (or even if it was a command) before doing some things on a script (was checking farther down), which caused my script to loop a 'sendChat' in it over and over again. I was checking to see if a character sent the command, before I even checked if it was suppose to go that far..so anything sending any chat spammed "Not a character" which then triggered it saying THAT wasnt a character..and loop forever :P The firing of on message when it sends a message is correct, since technically it is a chat message being sent. just it should stop once it hits a check to see if its a message it cares about. Perhaps post one of the scripts that's looping so we can look? If I cant help, maybe someone else will see it and be able to spot it.
1390948071
Chad
Sheet Author
Oh, I'm not worried about my scripts :) Mine check fairly carefully to make sure. I'm worried about some other scripts... Some scripts have multiple "on:message" events, for example, instead of just one "on:message" that parses everything... Some scripts trigger themselves a couple times. Not an endless loop, but when I put a log entry at the beginning of various "on message" events I got many lines of log before the script stopped triggering itself. Thus calling it a bug. When badly written scripts can create pointless loops like that, the scripting engine needs a tweak.
1390948407
DXWarlock
Sheet Author
API Scripter
Ah I got ya, never tried it that way, it could be a bug in the way it processes scripts with multiple on event commands. maybe a developer can poke in and answer it. I always do one trigger, then a lot of checks, like: on("chat:message", function (msg) { var cmdName1 = "!command1 "; var cmdName2 = "!command2 "; var cmdName3 = "!command3 "; if(msg.type == "api" && msgTxt.indexOf(cmdName1) !== -1) { (do stuff here) } if(msg.type == "api" && msgTxt.indexOf(cmdName2) !== -1) { (do stuff here) } if(msg.type == "api" && msgTxt.indexOf(cmdName3) !== -1) { (do stuff here) } }
1390951350

Edited 1390951528
Chad
Sheet Author
Me too. Generally a switch statement preeceeded by: if (msg.type !== "api") return; //Immediately ignore any message that isn't an API call (Starts with !) if (msg.type == "api" && msg.content.indexOf("!Prefix") == 0) { //Ignore any message not containing expected prefix That way I exit the event immediately if it's not an API and I don't do any processing if it doesn't have the prefix I expect.