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

on('chat:message', handleInput) repeating

1468830725
Jakob
Sheet Author
API Scripter
I have some scripts that listen to chat messages via some form of on('chat:message', handleInput) in registerEventHandlers. Sometimes (I can't really seem to find clear conditions under which I can reproduce it) the script will run multiple times reacting to a single message, sometimes it will even keep reacting to the same message ad infinitum . Am I doing something wrong to cause that? There's no condition in my handleInput that would cause it to loop through itself, so it must be the case that handleInput is called repeatedly. Can I prevent that from happening? Why is it even happening? Can a single chat message cause multiple chat:message events?
1468844688
The Aaron
Pro
API Scripter
Can you post a link to your code?  Usually the problem with duplicates is either registering the handler more than once or not properly filtering out messages that are being sent in response to messages received (infinite loop)
1468846093
Jakob
Sheet Author
API Scripter
It's at&nbsp; <a href="https://github.com/joesinghaus/roll20-scripts/blob" rel="nofollow">https://github.com/joesinghaus/roll20-scripts/blob</a>... .
1468851437
The Aaron
Pro
API Scripter
Try replacing this: sendChat(msg.who, output, null, {noarchive:true}) with this: sendChat(msg.who, output); I seem to recall there being some bugs with the noarchive flag. &nbsp;Other than that, I don't see anything suspicious via static analysis. &nbsp;I'll try and run the script at some point and test.
1468851646
Jakob
Sheet Author
API Scripter
The Aaron said: Try replacing this: sendChat(msg.who, output, null, {noarchive:true}) with this: sendChat(msg.who, output); I seem to recall there being some bugs with the noarchive flag. &nbsp;Other than that, I don't see anything suspicious via static analysis. &nbsp;I'll try and run the script at some point and test. But I like noarchive &nbsp;:(. Ok, thanks for having a look.
1468852746
The Aaron
Pro
API Scripter
Yeah, I like the idea of noarchive. &nbsp;Definitely let us know if that doesn't fix it. &nbsp;If you can get it down to a minimal reproducible case, maybe we can get it fixed. =D
1468871494

Edited 1468871541
Jakob
Sheet Author
API Scripter
It is definitely caused by noarchive. I can't exactly reproduce it, but I managed to do it with only the following ingredients, mixed freely (on a new game with only 1 script, to make sure). After a bit of pushing buttons, the bug is sure to appear. restarting the script engine reloading the tabletop (to get stuff into archive) running !exposebug and !exposebug --1 a couple of times I could never get it to appear without noarchive. var exposeBug = exposeBug || (function() { 'use strict'; var handleInput = function(msg) { if (msg.type !== "api") { return; } var args = msg.content.split(/\s+--/); if (args.shift() === '!exposebug') { if (args[0] === '1') { var output = "This is just a test"; } else { var output = "This is a different test"; }&nbsp; sendChat(msg.who, output,null,{noarchive:true}); } return; }, registerEventHandlers = function() { on('chat:message', handleInput); }; return { RegisterEventHandlers: registerEventHandlers }; }()); on('ready',function() { 'use strict'; exposeBug.RegisterEventHandlers(); });
1468871612
The Aaron
Pro
API Scripter
Awesome sauce! &nbsp;Thanks!