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 running in a continuous loop question.

1436640947
vÍnce
Pro
Sheet Author
Non-scripter here(no kidding, ha ha). Aaron was cool enough to post some examples for using the new "API utilizing 3d dice feature" that's now on the Dev. I just wanted to create a small script to run in the editor so I could see it in action. This is what I have, however when I run !test, it runs continuously in the background posting to chat every 5s or so. Not good. Please point out the error(s) in my code. Thanks //version: 1.0 //use !test to show an API roll with text. on('chat:message', function(msg) { if (msg.type == "api" && msg.content.indexOf("!test") !== -1) { sendChat(msg.who,"The person responsible for bringing the funyans and mountain dew next time is player [[1d6]]!", null, {use3d: true, noarchive: true}); } });
1436649231
Lithl
Pro
Sheet Author
API Scripter
The chat:message event is the only event type that can be triggered by the API, making it possible to create an infinite loop with sendChat in a chat:message event. However, the code you've posted shouldn't do that, because you're only calling sendChat if the message is "!test", and the message you're sending... isn't that. I have no idea why that code is causing a loop, but it may be a bug in the use3d or noarchive stuff on dev.
1436654862

Edited 1436656258
vÍnce
Pro
Sheet Author
Thanks Brian. I seem to have a knack at detecting bugs... just not solving them. lol
I bet it is looping because it 're-triggers the event without clearing the original msg object somehow. Stick a log(msg.content); in there and see what it is doing.
1436656142

Edited 1436656232
vÍnce
Pro
Sheet Author
API log just posts "!test" "!test" "!test" ... Over and over, until I disable the script.
I got some weird ass results when I tried this... it started sending random 3d6 rolls to chat or picking up old powercard script calls. However, I did find the source of your bug. It does not repeat if you do not have 3D dice enabled under your settings tab. It also does not repeat if you have noarchive set to false.
1436724292
vÍnce
Pro
Sheet Author
HoneyBadger said: I got some weird ass results when I tried this... it started sending random 3d6 rolls to chat or picking up old powercard script calls. However, I did find the source of your bug. It does not repeat if you do not have 3D dice enabled under your settings tab. It also does not repeat if you have noarchive set to false. Thanks HB. I'll pass this on in the Dev Update 7/7... thread.