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 .
Advertisement Create a free account

[Help] Message handling for multiple scripts

Hello all, I'm currently working with the wonderful PowerCards script plus three of my own custom scripts made for the warhammer40k rpgs, and I'm seeing some weird behavior with my scripts; basically, when I have multiple of my scripts enabled, occasional attempts to execute the scripts in roll20 No error, no warning, no anything. Running the same command again will usually result in success, although sometimes it fails multiple times in a row. I've got error handling in my scripts, and the API console isn't reporting any errors, so I'm not really sure what the problem is. Interestingly enough, when I disable two of my three scripts, everything works fine--so that would suggest to me that the problem lies in some sort of unforseen interaction between my scripts. Basically, all three of my scripts are wrappers for PowerCards; they format the PC string according to weapon/character attributes they retrieve from the charsheets and do some more complex formatting that PC can't handle itself. I had some trouble early on with these scripts interfering with each other, so each is in its own namespace and I've set up a separate 4th script to serve as the listener and message handler. Here's my handler: 40klistener As I'm a novice programmer, I'm sure I'm doing something terribly wrong here--I just can't figure out what. Am I handling my api messages wrong? How can I avoid these random lapses?
The Aaron
Forum Champion
API Scripter
My first thought was you were modifying msg.content (which is shared across invokations of 'chat:message') leading to later handlers not being triggered. However, I didn't see where you would be doing that (you alias it as msgtxt, but don't appear to make destructive changes to it), and if you're doing dispatch for all scripts in a single handler, that would t matter.  I'd start by logging the msg any time it's made it past msg.type === 'api' and see if it's doing what you expect. 
Might be the new character limit of 32,000 characters and powercards might be hitting that with all the css/html going through. If so, it would have been fucking nice if the devs had given us a heads up on that change.
The Aaron
Forum Champion
API Scripter
I'm hoping it's an oversight that will get fixed...
Sky/Aaron, Thanks for the suggestions! I tried dropping some sendChat() functions in various places in the script execution to see where it was hanging up, and it appears to make it from the listener successfully into the PC wrapper scripts, but the output just fizzles right before the wrapper script's actual call to PC (or inside PC itself). It's intermittent enough that I can't be sure, but disabling/editing the listener script to remove the other wrapper scripts seems to stop the problem, but I can't for the life of me figure out why. A few questions: 1. That 32k limit...what is the scope of that limit exactly?  2. Is there a better way to be debugging these scripts? I'm just using Chome + copious placement of sendChat() right now, and I imagine there's a better way to go about this.
The Aaron
Forum Champion
API Scripter
The log function outputs to the API console. That (nearly) 32k limit is on the length of the second argument to sendChat(). 

Edited 1500843016
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Wait, 32,000 character limit? when did this go into effect? Hadn't read Aaron's last reply. Ok, so the message that sendchat sends can't be more than 32k, that I can work with.
The Aaron
Forum Champion
API Scripter
Full details in this bug:&nbsp; <a href="" rel="nofollow"></a>
The Aaron said: I'm hoping it's an oversight that will get fixed... I hope you are right- but I smell profit margins being &nbsp;increased
KS Backer
Gary W. said: The Aaron said: I'm hoping it's an oversight that will get fixed... I hope you are right- but I smell profit margins being &nbsp;increased You and me both Gary.
Aaron et al., I think I found my issue. After examining the console logs I set up it appears that the listener+wrapper function were executing perfectly well, but the problem came with the wrapper's "handoff" to PC--as I originally wrote them they were just spitting the formatted PC command back into chat to be scooped up by the PC handler. I've since modified the scripts to directly call into the PowerCard.Process() function and that seems to have eliminated the issue, but I'll wait until I can stress test it with my players to say for sure. Thanks for y'all's help!
Yeah, it was designed to be sent directly to PowerCard.Process.&nbsp;