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

Script gives no error, but makes itself and all other scripts stop working

Entering the following as a New Script seems to cause all other loaded scripts to stop responding to messages, but no error appears on the console. Cna anyone see what's wrong? function processMessage(msg) { sendChat("MGPF",msg.content); } log("Here"); on("chat:message",function(msg) { if (msg.type == "api") { sendChat("MGPF",msg.content); processMessage(msg); } });
1585268483
Nick O.
Forum Champion
I think what's happening is you're creating an infinite loop - in your sendChat command, change msg.content to a string, like "hi", and then type anything into the chat box that starts with an ! (for example, !test) and you'll see that "hi" gets printed in chat over and over again infinitely, which I think would block input from other scripts.  Ultimately, what is it you want your script to do? We may be able to offer some advice based on that.
I was just trying to get something to print a response to start with! Where is the infinite loop there though? Does sendChat's output get seen as an api type message by the script that emitted it?
1585270754
The Aaron
Roll20 Production Team
API Scripter
That's exactly right.  If you switch out the sendChat() calls for just log() calls, you'll see that what your'e sending to chat is whatever you ran that was an API command.  You could also do something like: function processMessage(msg) { sendChat("MGPF",`Content: ${msg.content}`); } log("Here"); on("chat:message",function(msg) { if (msg.type == "api") { sendChat("MGPF",`Content: ${msg.content}`); processMessage(msg); } });
1585270845
The Aaron
Roll20 Production Team
API Scripter
The infinite loop is this. You enter: !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test Your script sends to chat the string !test Your script gets the api message !test ...